package com.avic.rong.userOrder.activity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.telephony.PhoneNumberUtils;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.avic.rong.BaseActivity;
import com.avic.rong.R;
import com.avic.rong.payUtil.JavaPayUtil;
import com.avic.rong.payUtil.PayVo;
import com.avic.rong.shoppingCar.api.ShoppingCarGoodsKuCunApi;
import com.avic.rong.userOrder.adapter.DiscountListAdapter;
import com.avic.rong.userOrder.adapter.KuaiDiWayListAdapter;
import com.avic.rong.userOrder.adapter.MemberCardListAdapter;
import com.avic.rong.userOrder.adapter.MoreProductsListAdapter;
import com.avic.rong.userOrder.adapter.PayWayAdapter;
import com.avic.rong.userOrder.api.AddOrUpdateUserAppreciationTicketApi;
import com.avic.rong.userOrder.api.GetCouponListApi;
import com.avic.rong.userOrder.api.GetHistoryInvoiceApi;
import com.avic.rong.userOrder.api.GetTotalAmountApi;
import com.avic.rong.userOrder.api.MemberCardApi;
import com.avic.rong.userOrder.api.OrderSubmitApi;
import com.avic.rong.userOrder.api.PaySubmitApi;
import com.avic.rong.userOrder.api.ShippingListApi;
import com.avic.rong.userOrder.api.SureOrderApi;
import com.avic.rong.userOrder.api.ToPayApi;
import com.avic.rong.userOrder.api.ZengZhiShuiApi;
import com.avic.rong.userOrder.bean.AddressListBean;
import com.avic.rong.userOrder.bean.AddressShowBean;
import com.avic.rong.userOrder.bean.DianZiFaPiaoBean;
import com.avic.rong.userOrder.bean.DiscountBean;
import com.avic.rong.userOrder.bean.GetComanyInvoiceBean;
import com.avic.rong.userOrder.bean.GetTotalAmountBean;
import com.avic.rong.userOrder.bean.HistoryLookBean;
import com.avic.rong.userOrder.bean.MemberCardBean;
import com.avic.rong.userOrder.bean.OrderSubmitBean;
import com.avic.rong.userOrder.bean.PayWayBean;
import com.avic.rong.userOrder.bean.ShippingListBean;
import com.avic.rong.userOrder.bean.SureOrderBean;
import com.avic.rong.userOrder.bean.ZengZhiShuiBean;
import com.avic.rong.userOrder.event.InformUpdate;
import com.avic.rong.utils.ConstantsUtils;
import com.avic.rong.utils.DateUtils;
import com.avic.rong.utils.DialogCustom;
import com.avic.rong.utils.GlideUtils;
import com.avic.rong.utils.MoneyShowUtils;
import com.avic.rong.utils.ToastTools;
import com.avic.rong.wedgit.MoneyView;
import com.bumptech.glide.Glide;
import com.example.minato.minastore.BaseResultEntity;
import com.example.minato.minastore.http.HttpManager;
import com.example.minato.minastore.listener.HttpOnNextListener;
import com.google.gson.Gson;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class OrderConfirmActivity extends BaseActivity {


    @BindView(R.id.ll_root)
    LinearLayout llRoot;
    @BindView(R.id.tv_user_name)
    TextView tvUserName;
    @BindView(R.id.tv_address_phone)
    TextView tvAddressPhone;
    @BindView(R.id.tv_address_name)
    TextView tvAddressName;
    @BindView(R.id.iv_product_one)
    ImageView ivProductOne;
    @BindView(R.id.iv_product_two)
    ImageView ivProductTwo;
    @BindView(R.id.iv_product_three)
    ImageView ivProductThree;
    @BindView(R.id.pay_order_subtract)
    TextView payOrderSubtract;
    @BindView(R.id.pay_order_num)
    TextView payOrderNum;
    @BindView(R.id.pay_order_add)
    TextView payOrderAdd;
    @BindView(R.id.soll_conent)
    ScrollView sollConent;
    @BindView(R.id.ll_submit_order)
    LinearLayout llSubmitOrder;
    @BindView(R.id.ll_more_products)
    LinearLayout llMoreProducts;
    @BindView(R.id.ll_kuaidi_way)
    LinearLayout ll_kuaidi_way;
    @BindView(R.id.ll_fapiao_message)
    LinearLayout ll_fapiao_message;
    @BindView(R.id.ll_member_zhekou)
    LinearLayout ll_member_zhekou;
    @BindView(R.id.ll_edit_address)
    LinearLayout ll_edit_address;
    @BindView(R.id.et_liuyan)
    EditText et_liuyan;
    @BindView(R.id.iv_alone_good_pic)
    ImageView ivAloneGoodPic;
    @BindView(R.id.tv_alone_good_name)
    TextView tvAloneGoodName;
    @BindView(R.id.tv_alone_good_subtitle)
    TextView tvAloneGoodSubtitle;
    @BindView(R.id.tv_alone_good_price)
    TextView tvAloneGoodPrice;
    @BindView(R.id.tv_alone_good_num)
    TextView tvAloneGoodNum;
    @BindView(R.id.tv_fapiao_type)
    TextView tvFapiaoType;
    @BindView(R.id.tv_kuaidi_way)
    TextView tvKuaidiWay;

//    @BindView(R.id.loading_layout)
//    LoadingLayout loading_layout;

    @BindView(R.id.tv_good_allprice)
    TextView tvGoodAllprice;
    @BindView(R.id.tv_good_yunfei)
    TextView tvGoodYunfei;
    @BindView(R.id.tv_good_member_zekou)
    TextView tvGoodMemberZekou;
    @BindView(R.id.tv_order_price)
    MoneyView tvOrderPrice;
    @BindView(R.id.ll_goods)
    LinearLayout llGoods;
    @BindView(R.id.tv_submit_order)
    TextView tvSubmitOrder;
    @BindView(R.id.tv_product_one_number)
    TextView tvProductOneNumber;
    @BindView(R.id.tv_product_two_number)
    TextView tvProductTwoNumber;
    @BindView(R.id.tv_product_three_number)
    TextView tvProductThreeNumber;
    @BindView(R.id.tv_goods_num)
    TextView tvGoodsNum;
    @BindView(R.id.rl_goods_one)
    RelativeLayout rlGoodsOne;
    @BindView(R.id.rl_goods_two)
    RelativeLayout rlGoodsTwo;
    @BindView(R.id.rl_goods_three)
    RelativeLayout rlGoodsThree;
    @BindView(R.id.tv_discounts)
    TextView tvDiscounts;
    @BindView(R.id.ll_discounts)
    LinearLayout llDiscounts;
    @BindView(R.id.ll_goods_num)
    LinearLayout ll_goods_num;
    @BindView(R.id.ll_member_card)
    LinearLayout llMemberCard;
    @BindView(R.id.tv_good_discount_zekou)
    TextView tvGoodDiscountZekou;
    @BindView(R.id.ll_discount_zekou)
    LinearLayout ll_discount_zekou;
    @BindView(R.id.tv_bottom_address)
    TextView tv_bottom_address;
    @BindView(R.id.tv_download_goods_hint)
    TextView tv_download_goods_hint;
    @BindView(R.id.ll_add_address)
    LinearLayout ll_add_address;

    @BindView(R.id.tv_unit_name)
    TextView tv_unit_name;


    //    @BindView(R.id.tv_member_card_dikou)
//    TextView tvMemberCardDikou;

    @BindView(R.id.tv_status)
    TextView tvStatus;
    @BindView(R.id.tv_goods_type)
    TextView tvGoodsType;
    @BindView(R.id.tv_goods_tel)
    TextView tvGoodsTel;
    @BindView(R.id.ll_pic_tag)
    LinearLayout llPicTag;
    @BindView(R.id.tv_goods_type_one)
    TextView tvGoodsTypeOne;
    @BindView(R.id.tv_goods_tel_one)
    TextView tvGoodsTelOne;
    @BindView(R.id.ll_pic_tag_one)
    LinearLayout llPicTagOne;
    @BindView(R.id.tv_goods_type_two)
    TextView tvGoodsTypeTwo;
    @BindView(R.id.tv_goods_tel_two)
    TextView tvGoodsTelTwo;
    @BindView(R.id.ll_pic_tag_two)
    LinearLayout llPicTagTwo;
    @BindView(R.id.tv_goods_type_three)
    TextView tvGoodsTypeThree;
    @BindView(R.id.tv_goods_tel_three)
    TextView tvGoodsTelThree;
    @BindView(R.id.ll_pic_tag_three)
    LinearLayout llPicTagThree;
    @BindView(R.id.tv_status_one)
    TextView tvStatusOne;
    @BindView(R.id.tv_status_two)
    TextView tvStatusTwo;
    @BindView(R.id.tv_status_three)
    TextView tvStatusThree;


    private LinearLayout ll_spread;
    private ImageView iv_spread;


    private int num = 1;
    private double v;
    private PopupWindow popupWindow;
    private boolean isAgreement = true;//勾选用户协议
    private RelativeLayout rl_close;
    private TextView tv_dianzi_fapiao;
    private TextView tv_zengzhi_fapiao;
    private TextView tv_unit;
    private TextView tv_personal;
    private LinearLayout ll_address;
    private LinearLayout ll_user_number;
    private TextView tv_spread;
    private TextView tv_history_look;
    private TextView tv_goods_message;
    private LinearLayout ll_unit;
    private LinearLayout ll_zengzhi_fapiao;
    private LinearLayout ll_dianzi_fapiao;
    private boolean GOODS_MESSAGE = true;

    //地址选择Code
    public static final int ADDRESS_REQUEST_CODE = 100;
    private EditText et_company_name;
    private EditText et_tax_tel;
    private EditText et_address_or_phone;
    private EditText et_bank_or_number;
    private EditText et_shoupiao_phone;
    private EditText et_shoupiao_email;


    private EditText et_company_name_zengzhi;
    private EditText et_tax_tel_zengzhi;
    private EditText et_register_address_zengzhi;
    private EditText et_register_phone_zengzhi;
    private EditText et_open_account_bank;
    private EditText et_bank_number_zengzhi;

    private TextView tv_confirm_btn;
    private TextView tv_type_hint;

    private ZengZhiShuiBean zengZhiShuiBean;


    //增值发票id
    private String TICKET_ID;

    //会员卡余额
    public String memberCardYuE = "";
    //会员卡抵扣
    private String memberCardDiKou = "";

    private SureOrderBean sureOrderBean;
    private SureOrderBean.HistoryInvoiceBean historyInvoice;

    private ArrayList<ShippingListBean> shipList = new ArrayList<>();

    private KuaiDiWayListAdapter kuaiDiWayListAdapter;

    private ArrayList<MemberCardBean> memberCardList = new ArrayList<>();

    private MemberCardListAdapter memberCardListAdapter;

    private View inflateMemberCard;
    private View inflateKuaiDiWay;
    private View inflateFaPiaoMessage;


    //快递ID
    private String kuaidiWayId;
    //会员卡ID
    public String memberCardId;
    //优惠卷ID
    private String youhuiJuanId;
    //优惠商品sku集合
    private String discountSkuMap;
    private String orderType;
    private String skuStr;

    private List<PayWayBean.PaymentListBean> paymentList = new ArrayList<>();
    private PayWayAdapter payWayAdapter;
    private int payId = -1;

    //    private DialogPay dialogPay;
    private JavaPayUtil javaPayUtil;

    private int DIANZI_OR_ZENGZHI = -1;
    private int UNIT_OR_PERSON = -1;
    private List<SureOrderBean.GoodsListBean> goodsList = new ArrayList<>();
    private MoreProductsListAdapter moreProductsListAdapter;
    private View productsShowView;
    private TextView tv_goods_num_pop;
    private View discountDialog;
    private DiscountListAdapter discountListAdapter;
    private String skuStrDetail;
    private OrderSubmitBean orderSubmitBean;

    private List<DiscountBean> discountList = new ArrayList<>();
    private int addressId;

    public static String ORDER_ID = "order_id";
    public static String ORDER_SN = "order_sn";
    private int COMMENT_FORCODE = 6;

    private SureOrderBean.GoodsListBean goodsListBean;
    private String enterType = null;

    private int payeeId;

    private DianZiFaPiaoBean dianZiFaPiaoBean;

    public TextView tv_member_card_dikou;


    private GetTotalAmountBean getTotalAmountBean;

    public SureOrderBean.VipServiceBean vipServiceBean;

    public EditText et_use_yue;


    private TextView tv_no_member_card;

    private TextView tv_member_configm_btn;


    @Override
    protected int getContentViewId() {
        return R.layout.activity_order_confirm;
    }

    public void initView() {


        tv_member_card_dikou = findViewById(R.id.tv_member_card_dikou);

        EventBus.getDefault().register(this);
        ButterKnife.bind(this);
        ivRight.setImageResource(R.mipmap.gouwuche_dot);
        if (!TextUtils.isEmpty(getIntent().getStringExtra("orderType")) && !TextUtils.isEmpty(getIntent().getStringExtra("skuStr"))) {
            if (getIntent().getIntExtra("againBuy", 0) == 100) {
                enterType = getIntent().getStringExtra("enterType");
            }
            orderType = getIntent().getStringExtra("orderType");
            skuStr = getIntent().getStringExtra("skuStr");

        } else {
//            orderType = getIntent().getStringExtra("orderType");
            skuStr = getIntent().getStringExtra("skuStr");
            enterType = getIntent().getStringExtra("enterType");

        }
        tvTitle.setText("订单确认");
        et_liuyan.clearFocus();
        v = Double.parseDouble("10");

        moreFindViewById();

        //订单商品列表请求
        confirmOrderData();
        //优惠券列表
        discountListReq();


    }

    private String dealNumber(String money) {

        BigDecimal bigDecimal = new BigDecimal(Double.parseDouble(money));//不以科学计数法显示，正常显示保留两位小数

        return bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP) + "";
    }

    private void discountListReq() {
        if (!getSharedPreferencesUtil().getLogintoken().isEmpty()) {

            Map<String, String> paramBody = new HashMap<>();
            final GetCouponListApi getCouponListApi = new GetCouponListApi(OrderConfirmActivity.this, simpleOnNextListenerDiscount);
            getCouponListApi.setCache(false);
            if (TextUtils.isEmpty(skuStr)) {
                Map<Object, Object> skuStrMap = new HashMap<>();
                skuStrMap.put(89225, 1);
                skuStrMap.put(89226, 1);
                Gson gson = new Gson();
                String str = gson.toJson(skuStrMap);
                str = str.replace("\"", "");
                paramBody.put("skuStr", str);

            } else {
                skuStr = skuStr.replace("\"", "");
                paramBody.put("skuStr", skuStr);
            }
            paramBody.put("token", getSharedPreferencesUtil().getLogintoken());
            getCouponListApi.setMap(paramBody);
            HttpManager.getInstance().doHttpDeal(getCouponListApi);

        }
    }

    HttpOnNextListener simpleOnNextListenerDiscount = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {
            discountList.clear();
            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showToast(OrderConfirmActivity.this, subjects.getMsg());
                return;
            }
            List<DiscountBean> listData = (List<DiscountBean>) subjects.getData();
            discountList.addAll(listData);
            discountListAdapter.notifyDataSetChanged();
        }


        @Override
        public void onCacheNext(String cache) {


        }


        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", e.getMessage());
        }
    };

    private void moreFindViewById() {
        //发票
        inflateFaPiaoMessage = LayoutInflater.from(OrderConfirmActivity.this).inflate(R.layout.fapiao_message_layout, null);

        rl_close = (RelativeLayout) inflateFaPiaoMessage.findViewById(R.id.rl_close);

        tv_dianzi_fapiao = (TextView) inflateFaPiaoMessage.findViewById(R.id.tv_dianzi_fapiao);

        tv_zengzhi_fapiao = (TextView) inflateFaPiaoMessage.findViewById(R.id.tv_zengzhi_fapiao);

        tv_unit = (TextView) inflateFaPiaoMessage.findViewById(R.id.tv_unit);

        tv_personal = (TextView) inflateFaPiaoMessage.findViewById(R.id.tv_personal);

        ll_address = (LinearLayout) inflateFaPiaoMessage.findViewById(R.id.ll_address);

        ll_user_number = (LinearLayout) inflateFaPiaoMessage.findViewById(R.id.ll_user_number);

        tv_spread = (TextView) inflateFaPiaoMessage.findViewById(R.id.tv_spread);
        ll_spread = (LinearLayout) inflateFaPiaoMessage.findViewById(R.id.ll_spread);
        iv_spread = (ImageView) inflateFaPiaoMessage.findViewById(R.id.iv_spread);

        tv_history_look = (TextView) inflateFaPiaoMessage.findViewById(R.id.tv_history_look);

        tv_goods_message = (TextView) inflateFaPiaoMessage.findViewById(R.id.tv_goods_message);

        ll_unit = (LinearLayout) inflateFaPiaoMessage.findViewById(R.id.ll_unit);

        ll_dianzi_fapiao = (LinearLayout) inflateFaPiaoMessage.findViewById(R.id.ll_dianzi_fapiao);

        ll_zengzhi_fapiao = (LinearLayout) inflateFaPiaoMessage.findViewById(R.id.ll_zengzhi_fapiao);

        et_company_name = inflateFaPiaoMessage.findViewById(R.id.et_company_name);
        et_tax_tel = inflateFaPiaoMessage.findViewById(R.id.et_tax_tel);
        et_address_or_phone = inflateFaPiaoMessage.findViewById(R.id.et_address_or_phone);
        et_bank_or_number = inflateFaPiaoMessage.findViewById(R.id.et_bank_or_number);
        et_shoupiao_phone = inflateFaPiaoMessage.findViewById(R.id.et_shoupiao_phone);
        et_shoupiao_email = inflateFaPiaoMessage.findViewById(R.id.et_shoupiao_email);


        et_company_name_zengzhi = inflateFaPiaoMessage.findViewById(R.id.et_company_name_zengzhi);
        et_tax_tel_zengzhi = inflateFaPiaoMessage.findViewById(R.id.et_tax_tel_zengzhi);
        et_register_address_zengzhi = inflateFaPiaoMessage.findViewById(R.id.et_register_address_zengzhi);
        et_register_phone_zengzhi = inflateFaPiaoMessage.findViewById(R.id.et_register_phone_zengzhi);
        et_open_account_bank = inflateFaPiaoMessage.findViewById(R.id.et_open_account_bank);
        et_bank_number_zengzhi = inflateFaPiaoMessage.findViewById(R.id.et_bank_number_zengzhi);


        tv_confirm_btn = inflateFaPiaoMessage.findViewById(R.id.tv_confirm_btn);
        tv_type_hint = inflateFaPiaoMessage.findViewById(R.id.tv_type_hint);

        tv_dianzi_fapiao.setSelected(true);
        tv_dianzi_fapiao.setTextColor(getResources().getColor(R.color.color_99C729));
        tv_unit.setSelected(true);
        tv_unit.setTextColor(getResources().getColor(R.color.color_99C729));


        //快递方式
        inflateKuaiDiWay = LayoutInflater.from(this).inflate(R.layout.kuaidi_way_layout, null);
        RecyclerView kuaidi_tag_list = (RecyclerView) inflateKuaiDiWay.findViewById(R.id.kuaidi_tag_list);
        RelativeLayout rl_close = (RelativeLayout) inflateKuaiDiWay.findViewById(R.id.rl_close);
        TextView tv_confirm_btn = (TextView) inflateKuaiDiWay.findViewById(R.id.tv_confirm_btn);
        kuaidi_tag_list.setLayoutManager(new GridLayoutManager(this, 3));
        kuaiDiWayListAdapter = new KuaiDiWayListAdapter(this, shipList);
        kuaidi_tag_list.setAdapter(kuaiDiWayListAdapter);

        //关闭按钮
        rl_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
            }
        });
        //确认按钮
        tv_confirm_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
            }
        });

        //会员卡
        inflateMemberCard = LayoutInflater.from(OrderConfirmActivity.this).inflate(R.layout.member_zekou_dialog, null);
        RecyclerView member_list = (RecyclerView) inflateMemberCard.findViewById(R.id.member_list);
        RelativeLayout rl_close_member = (RelativeLayout) inflateMemberCard.findViewById(R.id.rl_close);
        tv_member_configm_btn = (TextView) inflateMemberCard.findViewById(R.id.tv_configm_btn);
        tv_no_member_card = (TextView) inflateMemberCard.findViewById(R.id.tv_no_member_card);
        member_list.setLayoutManager(new LinearLayoutManager(OrderConfirmActivity.this));


        memberCardListAdapter = new MemberCardListAdapter(OrderConfirmActivity.this, memberCardList);
        member_list.setAdapter(memberCardListAdapter);
        //关闭按钮
        rl_close_member.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
            }
        });

        tv_member_configm_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getTotalAmount(kuaidiWayId, memberCardId, youhuiJuanId);
                popupWindow.dismiss();
            }
        });
        //多商品展示
        productsShowView = LayoutInflater.from(this).inflate(R.layout.more_products_show_list, null);
        RecyclerView more_products_list = (RecyclerView) productsShowView.findViewById(R.id.more_products_list);
        LinearLayout ll_close = (LinearLayout) productsShowView.findViewById(R.id.ll_close);
        tv_goods_num_pop = (TextView) productsShowView.findViewById(R.id.tv_goods_num);
        more_products_list.setLayoutManager(new LinearLayoutManager(this));
        moreProductsListAdapter = new MoreProductsListAdapter(this, goodsList);
        more_products_list.setAdapter(moreProductsListAdapter);
        //关闭按钮
        ll_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
            }
        });


        //优惠券
        discountDialog = LayoutInflater.from(this).inflate(R.layout.discount_dialog, null);
        RecyclerView discount_list = (RecyclerView) discountDialog.findViewById(R.id.discount_list);
        RelativeLayout ll_close_discount = (RelativeLayout) discountDialog.findViewById(R.id.rl_close);
        discount_list.setLayoutManager(new LinearLayoutManager(this));
        discountListAdapter = new DiscountListAdapter(this, discountList);
        discount_list.setAdapter(discountListAdapter);
        //关闭按钮
        ll_close_discount.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
            }
        });
    }


    private void confirmOrderData() {
        if (!getSharedPreferencesUtil().getLogintoken().isEmpty()) {

            Map<String, String> paramBody = new HashMap<>();
            if (TextUtils.isEmpty(orderType)) {
                paramBody.put("orderType", "4");
            } else {
                paramBody.put("orderType", orderType);
            }

            paramBody.put("token", getSharedPreferencesUtil().getLogintoken());
            //订单商品列表请求
            final SureOrderApi sureOrderApi = new SureOrderApi(OrderConfirmActivity.this, simpleOnNextListenerConfirmOrder);
            sureOrderApi.setCache(false);
            sureOrderApi.setMap(paramBody);
            if (TextUtils.isEmpty(skuStr)) {
                Map<Object, Object> skuStrMap = new HashMap<>();
                skuStrMap.put(89225, 1);
//                skuStrMap.put(89226, 1);
                Gson gson = new Gson();
                String str = gson.toJson(skuStrMap);
                str = str.replace("\"", "");
                sureOrderApi.setSkuStr(str);

            } else {
                skuStr = skuStr.replace("\"", "");
                sureOrderApi.setSkuStr(skuStr);
            }

            HttpManager.getInstance().doHttpDeal(sureOrderApi);
//            loading_layout.setOnReloadListener(new LoadingLayout.OnReloadListener() {
//                @Override
//                public void onReload(View v) {
//                    HttpManager.getInstance().doHttpDeal(sureOrderApi);
//                    loading_layout.setStatus(LoadingLayout.LOADING);
//                }
//
//                @Override
//                public void onReturn(View v) {
//                    onBackPressed();
//                }
//            });
//            loading_layout.setStatus(LoadingLayout.LOADING);
        } else {
//            loading_layout.setStatus(LoadingLayout.EMPTY);
        }

    }

    @Override
    protected void addListener() {

    }

    public String getTICKET_ID() {
        return TICKET_ID;
    }

    public void setTICKET_ID(String TICKET_ID) {
        this.TICKET_ID = TICKET_ID;
    }

    private void commonPop(View view) {
        popupWindow = new PopupWindow(view);


        int height = getWindowManager().getDefaultDisplay().getHeight();
//        popupWindow.setHeight(height * 3 / 4);
        popupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        popupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        popupWindow.setFocusable(true);
        // 产生背景变暗效果
        WindowManager.LayoutParams lp = getWindow()
                .getAttributes();
        lp.alpha = 0.4f;
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        getWindow().setAttributes(lp);
        popupWindow.setBackgroundDrawable(new BitmapDrawable());
        popupWindow.setOutsideTouchable(false);
        popupWindow.setTouchable(true);
        //从下往上弹出动画效果
        popupWindow.setAnimationStyle(R.style.bottomPopupAnimation);
        popupWindow.showAtLocation(findViewById(R.id.ll_root), Gravity.BOTTOM, 0, 0);
        popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {

            // 在dismiss中恢复透明度
            public void onDismiss() {
                WindowManager.LayoutParams lp = getWindow()
                        .getAttributes();
                lp.alpha = 1f;
                getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
                getWindow().setAttributes(lp);
            }
        });
    }

    @OnClick({R.id.pay_order_subtract, R.id.pay_order_num, R.id.pay_order_add, R.id.ll_more_products, R.id.ll_kuaidi_way, R.id.ll_member_zhekou, R.id.tv_submit_order, R.id.ll_fapiao_message, R.id.ll_edit_address, R.id.ll_discounts, R.id.ll_add_address})
    public void onViewClicked(View view) {
        String price = tvAloneGoodPrice.getText().toString().trim();
        SureOrderBean.GoodsListBean goodsListBean = sureOrderBean.getGoodsList().get(0);
        Intent intent = null;
        switch (view.getId()) {
            case R.id.pay_order_subtract:

                if (num <= 1) {
                    ToastTools.showToast(this, "至少购买一个商品");
                    return;
                } else {
                    num--;
                }
                payOrderNum.setText(num + "");
                tvAloneGoodNum.setText("x" + num);
                if (goodsListBean == null) return;
                tvGoodAllprice.setText("¥" + dealNumber((Double.parseDouble(num + "") * Double.parseDouble(goodsListBean.getRealPrice() + "")) + ""));
                tvOrderPrice.setMoneyText("" + MoneyShowUtils.changTVsize(MoneyShowUtils.dealNumber((goodsListBean.getRealPrice() * num) + "")));
//                payOrderNum.setText("¥" + v * num);
                getTotalAmount(kuaidiWayId, memberCardId, youhuiJuanId);

                break;
            case R.id.pay_order_num:
                break;
            case R.id.pay_order_add:
                if (sureOrderBean.getGoodsList() != null && sureOrderBean.getGoodsList().size() > 0) {
                    int skuId = sureOrderBean.getGoodsList().get(0).getSkuId();
                    getKuCun(num + 1, skuId);
                }


//                payOrderNum.setText("¥" + v * num);
                break;
            case R.id.ll_more_products:
                //多商品查看
                moreProductsPop();
                break;
            case R.id.ll_kuaidi_way:
                //快递方式弹窗
                kuaidiWay();
                break;
            case R.id.ll_member_zhekou:
                if (TextUtils.isEmpty(kuaidiWayId)) {
                    ToastTools.showToast(OrderConfirmActivity.this, "请选择快递方式");
                    return;
                }
                memberCardListAdapter.setTag(-1);
                //会员折扣弹窗
                if (memberCardList.size() <= 0) {
                    memberZeKou();
                } else {
                    commonPop(inflateMemberCard);
                }

                break;
            case R.id.tv_submit_order:
                if (DateUtils.isFastDoubleClick()) return;
                //提交订单之前先获取总金额
//                getTotalAmountAndSubmitOrder(kuaidiWayId, memberCardId, 0 + "");
                //提交订单
                orderSubmit();
                break;
            case R.id.ll_fapiao_message:

                //发票信息
                faPiaoMessage();

                break;
            case R.id.ll_edit_address:
                //编辑地址
                if (addressId != -1 || addressId != 0) {
                    intent = new Intent(OrderConfirmActivity.this, AddressListActivity.class);
                    intent.putExtra("addressID", addressId);
                    intent.putExtra("intentType", "order");
                    startActivityForResult(intent, ADDRESS_REQUEST_CODE);
                }

                break;
            case R.id.ll_add_address:
                //添加地址
                intent = new Intent(OrderConfirmActivity.this, AddressListActivity.class);
                startActivityForResult(intent, ADDRESS_REQUEST_CODE);
                break;
            case R.id.ll_discounts://优惠券
                commonPop(discountDialog);
                break;
            default:
                break;
        }
    }

    //获取商品库存
    private void getKuCun(int num, int skuId) {
        ShoppingCarGoodsKuCunApi goodsKuCunApi = new ShoppingCarGoodsKuCunApi(this, simpleOnNextListenerKuCun, num, skuId);
        goodsKuCunApi.setCache(false);
        HttpManager.getInstance().doHttpDeal(goodsKuCunApi);
    }

    HttpOnNextListener simpleOnNextListenerKuCun = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {
            if (subjects.getCode().equals("0000")) {
                num++;
                payOrderNum.setText(num + "");
                tvAloneGoodNum.setText("x" + num);
                if (goodsListBean == null) return;
                tvGoodAllprice.setText("¥" + dealNumber((Double.parseDouble(num + "") * Double.parseDouble(goodsListBean.getRealPrice() + "")) + ""));
                getTotalAmount(kuaidiWayId, memberCardId, youhuiJuanId);
//                tvAloneGoodNum.setText(num + "");
//
//                tvOrderPrice.setText("  ¥" + goodsListBean.getRealPrice() * num);
            } else {
                ToastTools.showLongToast(context, "商品库存不足");
            }
        }

        @Override
        public void onCacheNext(String cache) {
        }

        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", "错误：" + e.getMessage());
        }
    };

    private void getTotalAmountAndSubmitOrder(String kuaidiWayId, String memberCardID, String youhuiJuanID) {
        Map<Object, Object> skuStrMap = new HashMap<>();
        skuStrMap.put(89225, 1);
        Gson gson = new Gson();
        String str = gson.toJson(skuStrMap);
        str = str.replace("\"", "");

        Map<String, String> paramBody = new HashMap<>();

        String price = tvAloneGoodPrice.getText().toString().trim();
        price = price.replace("¥", "");
        paramBody.put("goodsAmount", price);
        paramBody.put("couponId", youhuiJuanID);
        paramBody.put("serviceId", memberCardID);
        paramBody.put("shippingId", kuaidiWayId);
        paramBody.put("token", getSharedPreferencesUtil().getLogintoken());
        GetTotalAmountApi getTotalAmountApi = new GetTotalAmountApi((OrderConfirmActivity) context, simpleOnNextListenerGetTotalAmountAndSubmit);
        getTotalAmountApi.setCache(false);
        getTotalAmountApi.setMap(paramBody);
        getTotalAmountApi.setSkuStr(str);
        HttpManager.getInstance().doHttpDeal(getTotalAmountApi);
    }

    private void orderSubmit() {


        if (!getSharedPreferencesUtil().getLogintoken().isEmpty()) {
            Map<Object, Object> skuStrMap = new HashMap<>();
            skuStrMap.put(89225, 1);
            Gson gson = new Gson();
            String str = gson.toJson(skuStrMap);
            str = str.replace("\"", "");


            if (TextUtils.isEmpty(sureOrderBean.getOrderType() + "")) {
                ToastTools.showToast(OrderConfirmActivity.this, "没有获取到订单类型");
                return;
            } else if (TextUtils.isEmpty(tvOrderPrice.getMoneyText().toString().trim() + "")) {
                ToastTools.showToast(OrderConfirmActivity.this, "没有获取到商品总金额");
                return;
            } else if (TextUtils.isEmpty(discountSkuMap)) {
                ToastTools.showToast(OrderConfirmActivity.this, "没有获取到优惠商品sku集合");
                return;
            } else if (TextUtils.isEmpty(kuaidiWayId)) {
                ToastTools.showToast(OrderConfirmActivity.this, "请选择配送方式");
                return;
            } else if (!TextUtils.isEmpty(kuaidiWayId)) {
                if (!kuaidiWayId.equals("4")) {
                    if (addressId == 0 || addressId == -1) {
                        ToastTools.showToast(OrderConfirmActivity.this, "请填写收货地址");
                        return;
                    }
                }
            }


            int orderType = sureOrderBean.getOrderType();
            String goodsPrice = tvGoodAllprice.getText().toString().trim();
            goodsPrice = goodsPrice.replace("¥", "");

            String orderPrice = tvOrderPrice.getMoneyText().toString().trim();
            orderPrice = orderPrice.replace("¥", "");

            String order_LiuYan = et_liuyan.getText().toString().trim();
            String companyName = et_company_name.getText().toString().trim();
            String shouPiaoPhone = et_shoupiao_phone.getText().toString().trim();
            String shouPiaoEmail = et_shoupiao_email.getText().toString().trim();
            String goodsMessage = tv_goods_message.getText().toString().trim();
            String registerAddress = et_register_address_zengzhi.getText().toString().trim();
            String registerPhone = et_register_phone_zengzhi.getText().toString().trim();
            String openAccountBank = et_open_account_bank.getText().toString().trim();
            String bankNumberZengzhi = et_bank_number_zengzhi.getText().toString().trim();
            String taxTel = et_tax_tel.getText().toString().trim();
            String addressOrPhone = et_address_or_phone.getText().toString().trim();
            String bankOrNumber = et_bank_or_number.getText().toString().trim();
            String companyNameZengZhi = et_company_name_zengzhi.getText().toString();


            Map<String, Object> paramBody = new HashMap<>();

            //必填项
            paramBody.put("orderType", orderType + "");
            paramBody.put("token", getSharedPreferencesUtil().getLogintoken());
            paramBody.put("goodsAmount", goodsPrice);
            paramBody.put("orderAmount", orderPrice);
            if (TextUtils.isEmpty(youhuiJuanId)) {
                paramBody.put("couponId", "0");
            } else {
                paramBody.put("couponId", youhuiJuanId + "");
            }

            if (TextUtils.isEmpty(memberCardId)) {
                paramBody.put("serviceId", 0 + "");
            } else {
                paramBody.put("serviceId", memberCardId + "");
            }

            paramBody.put("discountSkuMap", discountSkuMap);
            paramBody.put("addressId", addressId + "");
            paramBody.put("postscript", order_LiuYan);
            paramBody.put("shippingId", kuaidiWayId);
            /**
             *  电子发票（invType=1）
             *             个人（invPayeeType=1）时
             *             invPayee：个人（单位名称，直接传参个人就行，必填）
             *             invContent：商品明细
             *             tel：18810421278（必填）
             *             email：5457@qq.com（非必填）
             */


            /**
             * 电子发票单位（invPayeeType=2）时
             * invPayee：中航（单位名,必填）
             * invPayeeNumber（纳税人识别号，非必填，如果填写需校验格式，15或者18位只能有大写子母和数字组成   /^[0-9A-Z]*$/g）
             * companyAddress：（地址及电话，非必填）
             * bank：工行  62717011055545（开户行及账号，非必填）
             * invContent：商品明细
             * tel：18810421278（必填）
             * email：5457@qq.com（非必填）
             */


            /**
             * 增值税专用发票（invType=2）
             * ticketId:(增票资质id，必填)
             * invPayee：中航（单位名,必填）
             * invPayeeNumber（纳税人识别号，非必填，如果填写需校验格式，15或者18位只能有大写子母和数字组成   /^[0-9A-Z]*$/g）
             * address：（注册地址，必填）
             * mobile：（注册电话，必填）
             * bank：工行 （开户行，必填）
             * blankNo:621788221(银行账号,必填)
             * invContent：商品明细
             * tel：18810421278（必填）
             * email：5457@qq.com（非必填）
             */
            Pattern pattern = Pattern.compile("^[0-9A-Z]*$");
            if (tv_dianzi_fapiao.isSelected() && tv_personal.isSelected()) {
                //必填
                paramBody.put("invType", "3");
                paramBody.put("invPayeeType", "1");
                if (TextUtils.isEmpty(goodsMessage)) {
                    ToastTools.showToast(this, "请完善发票信息！");
                    return;
                }
                paramBody.put("invContent", goodsMessage);
                if (TextUtils.isEmpty(shouPiaoPhone)) {
                    ToastTools.showToast(this, "请完善发票信息！");
                    return;
                }
                paramBody.put("tel", shouPiaoPhone);
                //非必填
                if (!TextUtils.isEmpty(shouPiaoEmail) && !shouPiaoEmail.equals("null")) {
                    paramBody.put("email", shouPiaoEmail);
                }
            } else if (tv_dianzi_fapiao.isSelected() && tv_unit.isSelected()) {
                //必填
                paramBody.put("invType", "3");
                paramBody.put("invPayeeType", "2");
                if (TextUtils.isEmpty(companyName)) {
                    ToastTools.showToast(this, "请完善发票信息！");
                    return;
                }
                paramBody.put("invPayee", companyName);
                if (TextUtils.isEmpty(shouPiaoPhone)) {
                    ToastTools.showToast(this, "请完善发票信息！");
                    return;
                }
                paramBody.put("tel", shouPiaoPhone);

                //非必填
                if (!TextUtils.isEmpty(taxTel) && !taxTel.equals("null") && pattern.matcher(taxTel).matches()) {
                    paramBody.put("invPayeeNumber", taxTel);
                }
                if (!TextUtils.isEmpty(addressOrPhone) && !addressOrPhone.equals("null")) {
                    paramBody.put("companyAddress", addressOrPhone);
                }
                if (!TextUtils.isEmpty(bankOrNumber) && !bankOrNumber.equals("null")) {
                    paramBody.put("bank", bankOrNumber);
                }
                if (!TextUtils.isEmpty(goodsMessage) && !goodsMessage.equals("null")) {
                    paramBody.put("invContent", goodsMessage);
                }
                if (!TextUtils.isEmpty(shouPiaoEmail) && !shouPiaoEmail.equals("null")) {
                    paramBody.put("email", shouPiaoEmail);
                }
            } else if (tv_zengzhi_fapiao.isSelected()) {
                //必填
                paramBody.put("invType", "2");
                if (TextUtils.isEmpty(getTICKET_ID())) {
                    ToastTools.showToast(this, "增票资质id");
                    return;
                }
                paramBody.put("ticketId", getTICKET_ID());
                if (TextUtils.isEmpty(companyNameZengZhi)) {
                    ToastTools.showToast(this, "请完善发票信息！");
                    return;
                }
                paramBody.put("invPayee", companyNameZengZhi);
                if (TextUtils.isEmpty(registerAddress)) {
                    ToastTools.showToast(this, "请完善发票信息！");
                    return;
                }
                paramBody.put("address", registerAddress);
                if (TextUtils.isEmpty(registerPhone)) {
                    ToastTools.showToast(this, "请完善发票信息！");
                    return;
                }
                paramBody.put("mobile", registerPhone);
                if (TextUtils.isEmpty(openAccountBank)) {
                    ToastTools.showToast(this, "请完善发票信息！");
                    return;
                }
                paramBody.put("bank", openAccountBank);
                if (TextUtils.isEmpty(bankNumberZengzhi)) {
                    ToastTools.showToast(this, "请完善发票信息！");
                    return;
                }
                paramBody.put("blankNo", bankNumberZengzhi);
                if (TextUtils.isEmpty(goodsMessage)) {
                    ToastTools.showToast(this, "请完善发票信息！");
                    return;
                }
                paramBody.put("invContent", goodsMessage);
                if (TextUtils.isEmpty(shouPiaoPhone)) {
                    ToastTools.showToast(this, "请完善发票信息！");
                    return;
                }
                paramBody.put("tel", shouPiaoPhone);
                //非必填
                if (!TextUtils.isEmpty(taxTel) && !taxTel.equals("null") && pattern.matcher(taxTel).matches()) {
                    paramBody.put("invPayeeNumber", taxTel);
                }
                if (!TextUtils.isEmpty(shouPiaoEmail) && !shouPiaoEmail.equals("null")) {
                    paramBody.put("email", shouPiaoEmail);
                }
            }


//            //2：增值税专用发票  3 : 电子发票
//            if (tv_dianzi_fapiao.isSelected()) {
//                paramBody.put("invType", "3");
//            } else {
//                paramBody.put("invType", "2");
//            }
//            //1：个人  2：单位
//            if (tv_unit.isSelected()) {
//                paramBody.put("invPayeeType", "2");
//            } else {
//                paramBody.put("invPayeeType", "1");
//            }
//            if (tv_unit.isSelected()) {
//                paramBody.put("invPayee", companyName);
//            } else {
//                paramBody.put("invPayee", "个人");
//            }
//
//            if (TextUtils.isEmpty(shouPiaoPhone)){
//                ToastTools.showToast(this,"没有填写发票手机号");
//                return;
//            }
//            paramBody.put("tel", shouPiaoPhone);
//
//            //非填项
//            paramBody.put("invPayeeNumber", "");
//            paramBody.put("companyAddress", "");
//            paramBody.put("blank", "");
//            paramBody.put("email", shouPiaoEmail);
//
//            if (TextUtils.isEmpty(goodsMessage)){
//                ToastTools.showToast(this,"没有获取到商品明细");
//                return;
//            }
//            paramBody.put("invContent",goodsMessage );


            //订单提交请求
            final OrderSubmitApi orderSubmitApi = new OrderSubmitApi(OrderConfirmActivity.this, simpleOnNextListenerOrderSubmit);
            orderSubmitApi.setCache(false);
            orderSubmitApi.setMap(paramBody);
            if (TextUtils.isEmpty(skuStrDetail)) return;

            orderSubmitApi.setSkuStr(skuStrDetail);
            HttpManager.getInstance().doHttpDeal(orderSubmitApi);

//            loading_layout.setOnReloadListener(new LoadingLayout.OnReloadListener() {
//                @Override
//                public void onReload(View v) {
//                    HttpManager.getInstance().doHttpDeal(orderSubmitApi);
//                    loading_layout.setStatus(LoadingLayout.LOADING);
//                }
//
//                @Override
//                public void onReturn(View v) {
//                    onBackPressed();
//                }
//            });
//            loading_layout.setStatus(LoadingLayout.LOADING);
        } else {
//            loading_layout.setStatus(LoadingLayout.EMPTY);
        }

    }

    private void faPiaoMessage() {
        if (sureOrderBean != null) {
            if (sureOrderBean.getOrderType() == 4 || sureOrderBean.getOrderType() == 6 || sureOrderBean.getOrderType() == 8) {
                tv_zengzhi_fapiao.setVisibility(View.GONE);
            } else {
                tv_zengzhi_fapiao.setVisibility(View.VISIBLE);
            }
        }

        //2：增值税专用发票  3 : 电子发票

        //1：个人  2：单位
        if (DIANZI_OR_ZENGZHI != -1) {
            if (DIANZI_OR_ZENGZHI == 3) {
                tv_dianzi_fapiao.setSelected(true);
                tv_zengzhi_fapiao.setSelected(false);
                tv_dianzi_fapiao.setTextColor(getResources().getColor(R.color.color_99C729));
                tv_zengzhi_fapiao.setTextColor(getResources().getColor(R.color.base_title_color));
                tv_type_hint.setText("融融网启动电子普通发票,订单完成后点击'我的-我的订单'查看发票");
                ll_dianzi_fapiao.setVisibility(View.VISIBLE);
                ll_zengzhi_fapiao.setVisibility(View.GONE);
            } else if (DIANZI_OR_ZENGZHI == 2) {
                tv_dianzi_fapiao.setSelected(false);
                tv_zengzhi_fapiao.setSelected(true);
                tv_dianzi_fapiao.setTextColor(getResources().getColor(R.color.base_title_color));
                tv_zengzhi_fapiao.setTextColor(getResources().getColor(R.color.color_99C729));
                tv_type_hint.setText("平台将在您提交订单付款后对该发票信息进行审核。审核通过后，开具发票");
            }
        }
        if (UNIT_OR_PERSON != -1) {
            if (UNIT_OR_PERSON == 1) {
                tv_unit.setSelected(false);
                tv_personal.setSelected(true);
                tv_unit.setTextColor(getResources().getColor(R.color.base_title_color));
                tv_personal.setTextColor(getResources().getColor(R.color.color_99C729));
            } else if (UNIT_OR_PERSON == 2) {
                tv_unit.setSelected(true);
                tv_personal.setSelected(false);
                tv_unit.setTextColor(getResources().getColor(R.color.color_99C729));
                tv_personal.setTextColor(getResources().getColor(R.color.base_title_color));
            }
        }

        if (tv_personal.isSelected()) {
            ll_unit.setVisibility(View.GONE);
        } else {
            ll_unit.setVisibility(View.VISIBLE);
        }


        tv_goods_message.setSelected(GOODS_MESSAGE);
        if (GOODS_MESSAGE) {
            tv_goods_message.setTextColor(getResources().getColor(R.color.color_99C729));
        } else {
            tv_goods_message.setTextColor(getResources().getColor(R.color.base_title_color));
        }

        if (dianZiFaPiaoBean != null) {
            et_shoupiao_email.setText(dianZiFaPiaoBean.getEmail() + "");
            et_shoupiao_phone.setText(dianZiFaPiaoBean.getPhoneTel());
        } else {
          /*  if (historyInvoice != null && historyInvoice.getEmail() != null) {
                et_shoupiao_email.setText(historyInvoice.getEmail() + "");
                et_shoupiao_phone.setText(historyInvoice.getTel());
            }*/
        }


        if (!getSharedPreferencesUtil().getLogintoken().isEmpty()) {
            Map<String, String> map = new HashMap<>();
            map.put("token", getSharedPreferencesUtil().getLogintoken());
            //历史单位开票信息请求
            final GetHistoryInvoiceApi getHistoryInvoiceApi = new GetHistoryInvoiceApi(OrderConfirmActivity.this, simpleOnNextListener);
            getHistoryInvoiceApi.setCache(false);
            getHistoryInvoiceApi.setMap(map);
            HttpManager.getInstance().doHttpDeal(getHistoryInvoiceApi);

//            loading_layout.setOnReloadListener(new LoadingLayout.OnReloadListener() {
//                @Override
//                public void onReload(View v) {
//                    HttpManager.getInstance().doHttpDeal(getHistoryInvoiceApi);
//                    loading_layout.setStatus(LoadingLayout.LOADING);
//                }
//
//                @Override
//                public void onReturn(View v) {
//                    onBackPressed();
//                }
//            });
//            loading_layout.setStatus(LoadingLayout.LOADING);
        } else {
//            loading_layout.setStatus(LoadingLayout.EMPTY);
        }

        //关闭按钮
        rl_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
            }
        });
        ll_spread.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String trim = tv_spread.getText().toString().trim();
                iv_spread.setPivotX(iv_spread.getWidth() / 2);
                iv_spread.setPivotY(iv_spread.getHeight() / 2);//支点在图片中心
                if (trim.equals("展开")) {
                    tv_spread.setText("收起");
                    ll_address.setVisibility(View.VISIBLE);
                    ll_user_number.setVisibility(View.VISIBLE);
                    iv_spread.setRotation(180);
                } else {
                    tv_spread.setText("展开");
                    ll_address.setVisibility(View.GONE);
                    ll_user_number.setVisibility(View.GONE);
                    iv_spread.setRotation(360);
                }

            }
        });
        tv_dianzi_fapiao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                tv_dianzi_fapiao.setSelected(true);
                tv_zengzhi_fapiao.setSelected(false);
                tv_dianzi_fapiao.setTextColor(getResources().getColor(R.color.color_99C729));
                tv_zengzhi_fapiao.setTextColor(getResources().getColor(R.color.base_title_color));


                ll_dianzi_fapiao.setVisibility(View.VISIBLE);
                ll_zengzhi_fapiao.setVisibility(View.GONE);
                DIANZI_OR_ZENGZHI = 3;
                tv_type_hint.setText("融融网启动电子普通发票,订单完成后点击'我的-我的订单'查看发票");
            }
        });
        tv_zengzhi_fapiao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                tv_dianzi_fapiao.setSelected(false);
                tv_zengzhi_fapiao.setSelected(true);
                tv_dianzi_fapiao.setTextColor(getResources().getColor(R.color.base_title_color));
                tv_zengzhi_fapiao.setTextColor(getResources().getColor(R.color.color_99C729));

                ll_dianzi_fapiao.setVisibility(View.GONE);
                ll_zengzhi_fapiao.setVisibility(View.VISIBLE);
                DIANZI_OR_ZENGZHI = 2;


                //增票资质信息请求
                ZengZhiShuiApi zengZhiShuiApi = new ZengZhiShuiApi(OrderConfirmActivity.this, simpleOnNextListenerZengZhi);
                zengZhiShuiApi.setCache(false);
                HttpManager.getInstance().doHttpDeal(zengZhiShuiApi);
            }
        });
        tv_unit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                tv_unit.setSelected(true);
                tv_personal.setSelected(false);

                tv_unit.setTextColor(getResources().getColor(R.color.color_99C729));
                tv_personal.setTextColor(getResources().getColor(R.color.base_title_color));

                ll_unit.setVisibility(View.VISIBLE);
                //2：增值税专用发票  3 : 电子发票

                //1：个人  2：单位
                UNIT_OR_PERSON = 2;
            }
        });
        tv_personal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                tv_unit.setSelected(false);
                tv_personal.setSelected(true);
                tv_unit.setTextColor(getResources().getColor(R.color.base_title_color));
                tv_personal.setTextColor(getResources().getColor(R.color.color_99C729));
                ll_unit.setVisibility(View.GONE);
                //2：增值税专用发票  3 : 电子发票

                //1：个人  2：单位
                UNIT_OR_PERSON = 1;
            }
        });
        tv_goods_message.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                GOODS_MESSAGE = !GOODS_MESSAGE;
                tv_goods_message.setSelected(GOODS_MESSAGE);
                if (GOODS_MESSAGE) {
                    tv_goods_message.setTextColor(getResources().getColor(R.color.color_99C729));
                } else {
                    tv_goods_message.setTextColor(getResources().getColor(R.color.base_title_color));
                }
            }
        });
        //历史抬头
        tv_history_look.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(OrderConfirmActivity.this, HistoryLookActivity.class);
                intent.putExtra("taiTouID", payeeId);
                startActivity(intent);
            }
        });

        //发票确认按钮
        tv_confirm_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                addOrUpdateZengZhi();

            }
        });


    }

    private void addOrUpdateZengZhi() {
        //2：增值税专用发票  3 : 电子发票

        //1：个人  2：单位
        Map<String, String> paramBody = new HashMap<>();
        if (tv_dianzi_fapiao.isSelected()) {

            String companyName = et_company_name.getText().toString().trim();
            String shouPiaoPhone = et_shoupiao_phone.getText().toString().trim();
            String goodsMessage = tv_goods_message.getText().toString().trim();

            Pattern pattern = Pattern.compile("^[0-9A-Z]*$");
            if (tv_dianzi_fapiao.isSelected() && tv_personal.isSelected()) {
                //必填
                if (TextUtils.isEmpty(goodsMessage)) {
                    ToastTools.showToast(this, "请填写发票明细");
                    return;
                }
                if (TextUtils.isEmpty(shouPiaoPhone)) {
                    ToastTools.showToast(this, "请填写手机号");
                    return;
                }
            } else if (tv_dianzi_fapiao.isSelected() && tv_unit.isSelected()) {
                //必填
                if (TextUtils.isEmpty(companyName)) {
                    ToastTools.showToast(this, "请填写单位名称");
                    return;
                }
                if (TextUtils.isEmpty(shouPiaoPhone)) {
                    ToastTools.showToast(this, "请填写手机号");
                    return;
                }
            }

            DIANZI_OR_ZENGZHI = 3;

            faPiaoShow();

            popupWindow.dismiss();
        } else {
            DIANZI_OR_ZENGZHI = 2;
          /*  String companyNameZengZhi = et_company_name_zengzhi.getText().toString().trim();
            String taxTelZengZhi = et_tax_tel_zengzhi.getText().toString().trim();
            String registerAddressZengZhi = et_register_address_zengzhi.getText().toString().trim();
            String registerPhoneZengZhi = et_register_phone_zengzhi.getText().toString().trim();
            String openAccountBank = et_open_account_bank.getText().toString().trim();
            String bankNumberZengZhi = et_bank_number_zengzhi.getText().toString().trim();
            if (StringUtil.isEmpty(et_company_name_zengzhi.getText().toString().trim())) {
                ToastTools.showToast(this, "单位名称不能为空");
                return;
            } else if (taxTelZengZhi.isEmpty()) {
                ToastTools.showToast(this, "纳税人识别号不能为空");
                return;
            } else if (registerAddressZengZhi.isEmpty()) {
                ToastTools.showToast(this, "注册地址不能为空");
                return;
            } else if (registerPhoneZengZhi.isEmpty()) {
                ToastTools.showToast(this, "注册电话不能为空");
                return;
            } else if (!isPhoneNumber(registerPhoneZengZhi)) {
                ToastTools.showToast(this, "注册电话格式不正确");
                return;
            } else if (openAccountBank.isEmpty()) {
                ToastTools.showToast(this, "开户银行不能为空");
                return;
            } else if (bankNumberZengZhi.isEmpty()) {
                ToastTools.showToast(this, "银行账号不能为空");
                return;
            }*/
            String order_LiuYan = et_liuyan.getText().toString().trim();
            String companyName = et_company_name_zengzhi.getText().toString().trim();
            String shouPiaoPhone = et_shoupiao_phone.getText().toString().trim();
            String shouPiaoEmail = et_shoupiao_email.getText().toString().trim();
            String goodsMessage = tv_goods_message.getText().toString().trim();
            String registerAddress = et_register_address_zengzhi.getText().toString().trim();
            String registerPhone = et_register_phone_zengzhi.getText().toString().trim();
            String openAccountBank = et_open_account_bank.getText().toString().trim();
            String bankNumberZengzhi = et_bank_number_zengzhi.getText().toString().trim();
            String taxTel = et_tax_tel_zengzhi.getText().toString().trim();
            String addressOrPhone = et_address_or_phone.getText().toString().trim();
            Pattern pattern = Pattern.compile("^[0-9A-Z]*$");
            //必填

            if (TextUtils.isEmpty(companyName)) {
                ToastTools.showToast(this, "请填写公司名称");
                return;
            }
            paramBody.put("companyName", companyName);
            if (TextUtils.isEmpty(registerAddress)) {
                ToastTools.showToast(this, "请填写注册地址");
                return;
            }
            paramBody.put("regAddress", registerAddress);
            if (TextUtils.isEmpty(registerPhone)) {
                ToastTools.showToast(this, "请填写注册电话");
                return;
            }
            paramBody.put("regMobile", registerPhone);
            if (TextUtils.isEmpty(openAccountBank)) {
                ToastTools.showToast(this, "请填写开户行");
                return;
            }
            paramBody.put("bank", openAccountBank);
            if (TextUtils.isEmpty(bankNumberZengzhi)) {
                ToastTools.showToast(this, "请填写银行账号");
                return;
            }
            paramBody.put("blankNo", bankNumberZengzhi);
            if (TextUtils.isEmpty(shouPiaoPhone)) {
                ToastTools.showToast(this, "请填写手机号");
                return;
            }
            if (shouPiaoPhone.length() != 11 && shouPiaoPhone.startsWith("1")) {
                ToastTools.showToast(this, "手机号不正确");
                return;
            }
            paramBody.put("tel", shouPiaoPhone);
            //非必填
            if (!TextUtils.isEmpty(taxTel) && !taxTel.equals("null") && pattern.matcher(taxTel).matches()) {
                paramBody.put("identificationNumber", taxTel);
            }
            if (!TextUtils.isEmpty(shouPiaoEmail) && !shouPiaoEmail.equals("null")) {
                paramBody.put("email", shouPiaoEmail);
            }


            if (getTICKET_ID() != null) {
                paramBody.put("ticketId", getTICKET_ID());
            }

            paramBody.put("token", getSharedPreferencesUtil().getLogintoken());

            //添加或者修改增票信息请求
            AddOrUpdateUserAppreciationTicketApi addOrUpdateUserAppreciationTicketApi = new AddOrUpdateUserAppreciationTicketApi(OrderConfirmActivity.this, simpleOnNextListenerAddOrUpdateZengZhi);
            addOrUpdateUserAppreciationTicketApi.setCache(false);
            addOrUpdateUserAppreciationTicketApi.setMap(paramBody);
            HttpManager.getInstance().doHttpDeal(addOrUpdateUserAppreciationTicketApi);
        }

    }

    //发票回显
    private void faPiaoShow() {


        //增值发票的公司名称
        String companyNameCengZhi = et_company_name_zengzhi.getText().toString().trim();

        String companyName = et_company_name.getText().toString().trim();
        String taxTel = et_tax_tel.getText().toString().trim();
        String addressOrPhone = et_address_or_phone.getText().toString().trim();
        String bankOrNumber = et_bank_or_number.getText().toString().trim();
        String shoupiaoPhone = et_shoupiao_phone.getText().toString().trim();
        String shoupiaoEmail = et_shoupiao_email.getText().toString().trim();
        DianZiFaPiaoBean dianZiFaPiaoBean = new DianZiFaPiaoBean();
        dianZiFaPiaoBean.setCompanyName(companyName);
        dianZiFaPiaoBean.setDiscernNumber(taxTel);
        dianZiFaPiaoBean.setAddressOrPhone(addressOrPhone);
        dianZiFaPiaoBean.setBankNumber(bankOrNumber);
        dianZiFaPiaoBean.setEmail(shoupiaoEmail);
        dianZiFaPiaoBean.setPhoneTel(shoupiaoPhone);


        this.dianZiFaPiaoBean = dianZiFaPiaoBean;

        if (tv_zengzhi_fapiao.isSelected()) {
//            if (tv_personal.isSelected()){
//                tvFapiaoType.setText("增值税专用(商品明细-");
//                tv_unit_name.setText("个人");
//                tv_unit_name.setTextColor(getResources().getColor(R.color.base_subtitle_color));
//            }else if (tv_unit.isSelected()){
//                tvFapiaoType.setText("增值税专用(商品明细-");
//                if (TextUtils.isEmpty(companyNameCengZhi)){
//                    tv_unit_name.setText("请输入单位名称");
//                    tv_unit_name.setTextColor(getResources().getColor(R.color.red_dot_color));
//                }else {
//                    tv_unit_name.setText( companyNameCengZhi+ "");
//                    tv_unit_name.setTextColor(getResources().getColor(R.color.base_subtitle_color));
//                }
//            }
            tvFapiaoType.setText("增值税专用(商品明细-");
            if (TextUtils.isEmpty(companyNameCengZhi)) {
                tv_unit_name.setText("请输入单位名称");
                tv_unit_name.setTextColor(getResources().getColor(R.color.red_dot_color));
            } else {
                tv_unit_name.setText(companyNameCengZhi + "");
                tv_unit_name.setTextColor(getResources().getColor(R.color.base_subtitle_color));
            }

        } else if (tv_dianzi_fapiao.isSelected()) {
            if (tv_personal.isSelected()) {
                tvFapiaoType.setText("电子(商品明细-");
                tv_unit_name.setText("个人");
                tv_unit_name.setTextColor(getResources().getColor(R.color.base_subtitle_color));
            } else if (tv_unit.isSelected()) {
                tvFapiaoType.setText("电子(商品明细-");
                if (TextUtils.isEmpty(companyName)) {
                    tv_unit_name.setText("请输入单位名称");
                    tv_unit_name.setTextColor(getResources().getColor(R.color.red_dot_color));
                } else {
                    tv_unit_name.setText(companyName + "");
                    tv_unit_name.setTextColor(getResources().getColor(R.color.base_subtitle_color));
                }
            }
        }
         /*  if (TextUtils.isEmpty(companyName)){
               tv_unit_name.setText("请输入单位名称");
               tv_unit_name.setTextColor(getResources().getColor(R.color.red_dot_color));
            } else if (tv_unit.isSelected()){
                tv_unit_name.setText(companyName);
               tv_unit_name.setTextColor(getResources().getColor(R.color.base_subtitle_color));
            } else {
                tv_unit_name.setText("个人");
               tv_unit_name.setTextColor(getResources().getColor(R.color.base_subtitle_color));
            }*/


        //2：增值税专用发票  3 : 电子发票
        //1：个人  2：单位
          /*  if (DIANZI_OR_ZENGZHI == 2) {
                if (UNIT_OR_PERSON == 1) {

                } else if (UNIT_OR_PERSON == 2) {

                }

            } else if (DIANZI_OR_ZENGZHI == 3) {
                if (UNIT_OR_PERSON == 1) {

                } else if (UNIT_OR_PERSON == 2) {

                }
            }*/


    }


    private void selectPay(PayWayBean data) {
        View inflate = LayoutInflater.from(this).inflate(R.layout.select_pay_way_layout, null);
        RelativeLayout rl_close = (RelativeLayout) inflate.findViewById(R.id.rl_close);
//        final ImageView chat_btn = (ImageView) inflate.findViewById(R.id.chat_btn);
//        final ImageView ali_btn = (ImageView) inflate.findViewById(R.id.ali_btn);
//        final ImageView zhuanzhang_btn = (ImageView) inflate.findViewById(R.id.zhuanzhang_btn);
//        final ImageView yue_btn = (ImageView) inflate.findViewById(R.id.yue_btn);
//        final ImageView shop_pay_btn = (ImageView) inflate.findViewById(R.id.shop_pay_btn);
        RecyclerView recy_list = inflate.findViewById(R.id.recy_list);
        final ImageView iv_agree = (ImageView) inflate.findViewById(R.id.iv_agree);
        final TextView tv_submit_order = (TextView) inflate.findViewById(R.id.tv_submit_order);
        final TextView tv_pay_agreen = (TextView) inflate.findViewById(R.id.tv_pay_agreen);
        et_use_yue = (EditText) inflate.findViewById(R.id.et_use_yue);
        final LinearLayout ll_use_yue = (LinearLayout) inflate.findViewById(R.id.ll_use_yue);

        if (sureOrderBean == null) return;

        String orderPriceSubmit = tvOrderPrice.getMoneyText().toString();
        orderPriceSubmit = orderPriceSubmit.replace("¥", "");
        tv_submit_order.setText("确认付款 ¥" + MoneyShowUtils.dealNumber(orderPriceSubmit));
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        recy_list.setLayoutManager(linearLayoutManager);
        payWayAdapter = new PayWayAdapter(this, paymentList);
        recy_list.setAdapter(payWayAdapter);
        int orderType = sureOrderBean.getOrderType();
        payWayAdapter.setOrderType(orderType);

        //只有ordertype==4才有余额支付
        if (sureOrderBean != null) {
            if (orderType == 4) {
                ll_use_yue.setVisibility(View.VISIBLE);
            } else {
                ll_use_yue.setVisibility(View.GONE);
            }

        }

        payWayAdapter.setYueMoney(data.getUserMoney());
        payWayAdapter.setOrderPrice(orderPriceSubmit);
        payWayAdapter.notifyDataSetChanged();

        //用户支付协议应默认为勾选状态
        iv_agree.setSelected(isAgreement);
//        chat_btn.setRJCPSelected(true);
        commonPop(inflate);
        //关闭按钮
        rl_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DialogCustom.showDoubleDialog(OrderConfirmActivity.this, "", "确认放弃付款？", "确认离开", "继续支付", new DialogCustom.CustomDialogDouble() {
                    @Override
                    public void rightButtonClicked() {

                    }

                    @Override
                    public void leftButtonClicked() {
                        if (orderType != 5) {
                            Intent intent = new Intent(context, OrderDetailsActivity.class);
                            intent.putExtra(ORDER_ID, orderSubmitBean.getOrderId() + "");

                            ((Activity) context).startActivityForResult(intent, COMMENT_FORCODE);
                        } else {
                            Intent intent = new Intent(context, OrderDetailsPXActivity.class);
                            intent.putExtra(ORDER_SN, orderSubmitBean.getOrderNumber() + "");

                            ((Activity) context).startActivityForResult(intent, COMMENT_FORCODE);
                        }
                        popupWindow.dismiss();
                    }
                });

            }
        });
        String finalOrderPriceSubmit = orderPriceSubmit;
        et_use_yue.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

                if (TextUtils.isEmpty(s.toString())) {
                    tv_submit_order.setText("确认付款 ¥" + MoneyShowUtils.dealNumber(finalOrderPriceSubmit));
                    return;
                }
                if ((Double.parseDouble(finalOrderPriceSubmit) - Double.parseDouble(s.toString())) < 0) {
                    ToastTools.showToast(OrderConfirmActivity.this, "使用余额的金额应不能大于付款金额");
                    et_use_yue.setText(finalOrderPriceSubmit);
                } else if ((data.getUserMoney() - Double.parseDouble(s.toString())) < 0) {
                    ToastTools.showToast(OrderConfirmActivity.this, "使用余额的金额应不能大于所剩余额");
                    et_use_yue.setText(data.getUserMoney() + "");
                } else {
                    //payId != 5 &&
                    if (payId != -1) {
                        tv_submit_order.setText("确认付款 ¥" + MoneyShowUtils.dealNumber((Double.parseDouble(finalOrderPriceSubmit) - Double.parseDouble(s.toString())) + ""));
                    }
                }

            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

        //列表点击事件
        payWayAdapter.setOnClickItem(new PayWayAdapter.OnClickItem() {
            @Override
            public void OnClickListion(View view, int postion) {
                if (paymentList != null && paymentList.size() > 0) {
                    payId = paymentList.get(postion).getPayId();
                }
                payWayAdapter.setmSelectedPos(postion);

                if (payId == 5) {
                    String orderPriceSubmit = tvOrderPrice.getMoneyText().toString();
                    orderPriceSubmit = orderPriceSubmit.replace("¥", "");
                    et_use_yue.setText(MoneyShowUtils.dealNumber(orderPriceSubmit));

                } else {
                    et_use_yue.setText("");
                }

                payWayAdapter.notifyDataSetChanged();
            }
        });
        //支付协议
        tv_pay_agreen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(OrderConfirmActivity.this, PayAgreenActivity.class);
                startActivity(intent);
            }
        });
//        chat_btn.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onUpTimeClick(View v) {
//                chat_btn.setRJCPSelected(true);
//                ali_btn.setRJCPSelected(false);
//                zhuanzhang_btn.setRJCPSelected(false);
//                yue_btn.setRJCPSelected(false);
//                shop_pay_btn.setRJCPSelected(false);
//                Toast.makeText(OrderConfirmActivity.this, "点击了", Toast.LENGTH_SHORT).show();
//            }
//        });
//        ali_btn.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onUpTimeClick(View v) {
//                chat_btn.setRJCPSelected(false);
//                ali_btn.setRJCPSelected(true);
//                zhuanzhang_btn.setRJCPSelected(false);
//                yue_btn.setRJCPSelected(false);
//                shop_pay_btn.setRJCPSelected(false);
//            }
//        });
//        zhuanzhang_btn.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onUpTimeClick(View v) {
//                chat_btn.setRJCPSelected(false);
//                ali_btn.setRJCPSelected(false);
//                zhuanzhang_btn.setRJCPSelected(true);
//                yue_btn.setRJCPSelected(false);
//                shop_pay_btn.setRJCPSelected(false);
//            }
//        });
//        yue_btn.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onUpTimeClick(View v) {
//                chat_btn.setRJCPSelected(false);
//                ali_btn.setRJCPSelected(false);
//                zhuanzhang_btn.setRJCPSelected(false);
//                yue_btn.setRJCPSelected(true);
//                shop_pay_btn.setRJCPSelected(false);
//            }
//        });
//        shop_pay_btn.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onUpTimeClick(View v) {
//                chat_btn.setRJCPSelected(false);
//                ali_btn.setRJCPSelected(false);
//                zhuanzhang_btn.setRJCPSelected(false);
//                yue_btn.setRJCPSelected(false);
//                shop_pay_btn.setRJCPSelected(true);
//            }
//        });
        //同意条款
        iv_agree.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                isAgreement = !isAgreement;
                iv_agree.setSelected(isAgreement);
            }
        });
        //付款提交
        tv_submit_order.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ////payId  2  微信支付   3     支付宝     4    银行汇款/转账     6   到店支付     5   余额支付
                String useYue = et_use_yue.getText().toString().trim();
                String submitMoney = tv_submit_order.getText().toString().trim();
                submitMoney = submitMoney.replace("确认付款 ¥", "");
               /* if (Double.parseDouble(submitMoney) <= 0) {
                    if (payId == 2 || payId == 3 || payId == 4 || payId == 6) {
                        ToastTools.showLongToast(OrderConfirmActivity.this, "支付金额为0，请选择余额支付");
                        return;
                    }

                }*/
                if (!iv_agree.isSelected()) {
                    ToastTools.showLongToast(OrderConfirmActivity.this, "同意条款才能进行支付");
                    return;
                } else if (payId != -1 && payId == 5) {
                   /* if (!TextUtils.isEmpty(useYue)) {
                        ToastTools.showLongToast(OrderConfirmActivity.this, "选择余额支付后无需填写余额");
                        return;
                    } else*/
                    if (Double.parseDouble(submitMoney) > data.getUserMoney()) {
                        ToastTools.showLongToast(OrderConfirmActivity.this, "余额不足请充值或选择其他支付方式！");
                        return;
                    }
                } else if (payId != -1 && payId != 5) {
                    String orderPriceSubmit = tvOrderPrice.getMoneyText().toString();
                    orderPriceSubmit = orderPriceSubmit.replace("¥", "");
                    if (!TextUtils.isEmpty(useYue)) {
                        if (Double.parseDouble(useYue) > Double.parseDouble(orderPriceSubmit)) {
                            ToastTools.showLongToast(OrderConfirmActivity.this, "您选择了混合的支付方式，请填写正确的金额");
                            return;
                        }
                    }

                } else if (data.getUserMoney() <= 0) {
                    useYue = "0.00";
                } else if (payWayAdapter.getBalancePayId() == -1 && payId == -1) {
                    ToastTools.showLongToast(OrderConfirmActivity.this, "请选择支付方式！");
                    return;
                } else if (data.getUserMoney() < Double.parseDouble(submitMoney)) {
                    ToastTools.showLongToast(OrderConfirmActivity.this, "您当前余额不足！");
                    return;
                }/*else if (payId == -1) {
                    ToastTools.showLongToast(OrderConfirmActivity.this, "请选择支付方式！");
                    return;
                }*/
                if (payId == 5) {
                    paySubmit(useYue);
                } else {
                    paySubmit(useYue);
                }

            }
        });


    }

    private void paySubmit(String use_yue) {
        if (!getSharedPreferencesUtil().getLogintoken().isEmpty()) {
            Map<String, String> paramsBody = new HashMap<>();
            if (orderSubmitBean == null) return;
            paramsBody.put("orderId", orderSubmitBean.getOrderId() + "");
            paramsBody.put("token", getSharedPreferencesUtil().getLogintoken());

            if (payWayAdapter.getBalancePayId() == -1 && payId == -1) {
                ToastTools.showToast(OrderConfirmActivity.this, "请选择支付方式");
                return;
            }
            paramsBody.put("payId", payId + "");
            if (!TextUtils.isEmpty(use_yue)) {
                paramsBody.put("balance", use_yue);
            } else {
                paramsBody.put("balance", 0 + "");
            }

            //支付提交
            final PaySubmitApi paySubmitApi = new PaySubmitApi(OrderConfirmActivity.this, simpleOnNextListenerPaySubmit);
            paySubmitApi.setCache(false);
            paySubmitApi.setMap(paramsBody);
            HttpManager.getInstance().doHttpDeal(paySubmitApi);

//            loading_layout.setOnReloadListener(new LoadingLayout.OnReloadListener() {
//                @Override
//                public void onReload(View v) {
//                    HttpManager.getInstance().doHttpDeal(paySubmitApi);
//                    loading_layout.setStatus(LoadingLayout.LOADING);
//                }
//
//                @Override
//                public void onReturn(View v) {
//                    onBackPressed();
//                }
//            });
//            loading_layout.setStatus(LoadingLayout.LOADING);
        } else {
//            loading_layout.setStatus(LoadingLayout.EMPTY);
        }
    }

    private void memberZeKou() {


        if (!getSharedPreferencesUtil().getLogintoken().isEmpty()) {


            Map<String, String> map = new HashMap<>();
            map.put("token", getSharedPreferencesUtil().getLogintoken());

            if (TextUtils.isEmpty(skuStr)) {
                Map<Object, Object> skuStrMap = new HashMap<>();
                skuStrMap.put(89225, 1);
                Gson gson = new Gson();
                String str = gson.toJson(skuStrMap);
                str = str.replace("\"", "");
                map.put("skuStr", str);
            } else if (sureOrderBean != null && sureOrderBean.getGoodsList().size() == 1) {
//                skuStr = skuStr.replace("\"", "");
//                sureOrderApi.setSkuStr(skuStr);
                map.put("skuStr", skuStrDetail);
            } else {
                skuStr = skuStr.replace("\"", "");
//                sureOrderApi.setSkuStr(skuStr);
                map.put("skuStr", skuStr);
            }

            //会员卡列表
            final MemberCardApi memberCardApi = new MemberCardApi(OrderConfirmActivity.this, simpleOnNextListenerMemberCard);
            memberCardApi.setCache(false);
            memberCardApi.setMap(map);
            HttpManager.getInstance().doHttpDeal(memberCardApi);
//            loading_layout.setOnReloadListener(new LoadingLayout.OnReloadListener() {
//                @Override
//                public void onReload(View v) {
//                    HttpManager.getInstance().doHttpDeal(memberCardApi);
//                    loading_layout.setStatus(LoadingLayout.LOADING);
//                }
//
//                @Override
//                public void onReturn(View v) {
//                    onBackPressed();
//                }
//            });
//            loading_layout.setStatus(LoadingLayout.LOADING);
        } else {
//            loading_layout.setStatus(LoadingLayout.EMPTY);
        }


    }

    private void kuaidiWay() {


        if (!getSharedPreferencesUtil().getLogintoken().isEmpty()) {
            //配送方式列表
            final ShippingListApi shippingListApi = new ShippingListApi(OrderConfirmActivity.this, simpleOnNextListenerShipWay);
            shippingListApi.setCache(false);
            HttpManager.getInstance().doHttpDeal(shippingListApi);

          /*  loading_layout.setOnReloadListener(new LoadingLayout.OnReloadListener() {
                @Override
                public void onReload(View v) {
                    HttpManager.getInstance().doHttpDeal(shippingListApi);
                    loading_layout.setStatus(LoadingLayout.LOADING);
                }

                @Override
                public void onReturn(View v) {
                    onBackPressed();
                }
            });
            loading_layout.setStatus(LoadingLayout.LOADING);*/
        } else {
//            loading_layout.setStatus(LoadingLayout.EMPTY);
        }


    }

    public void moreProductsPop() {

        commonPop(productsShowView);


    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == Activity.RESULT_OK) {
            switch (requestCode) {
                case ADDRESS_REQUEST_CODE:
                    AddressListBean address_bean = (AddressListBean) data.getSerializableExtra("address_bean");
                    tvUserName.setText(address_bean.getConsignee());
                    tvAddressPhone.setText(address_bean.getTel() + "");
                    tvAddressName.setText(address_bean.getProvinceName() + address_bean.getCityName() + address_bean.getAddress() + "");
                    tv_bottom_address.setText(address_bean.getProvinceName() + address_bean.getCityName() + address_bean.getAddress() + "");
                    tv_bottom_address.setVisibility(View.VISIBLE);
                    this.addressId = address_bean.getAddressId();
                    ll_add_address.setVisibility(View.GONE);
                    ll_edit_address.setVisibility(View.VISIBLE);
                    break;
                default:
                    break;
            }
        }
    }

    public void getTotalAmount(String kuaidiWayId, String memberCardID, String youhuiJuanID) {
     /*   Map<Object, Object> skuStrMap = new HashMap<>();
        skuStrMap.put(89225, 1);
        Gson gson = new Gson();
        String str = gson.toJson(skuStrMap);
        str = str.replace("\"", "");*/

        Map<String, String> paramBody = new HashMap<>();

        String price = tvAloneGoodPrice.getText().toString().trim();
        String orderNum = payOrderNum.getText().toString().trim();
        price = price.replace("¥", "");
        if (sureOrderBean != null && sureOrderBean.getGoodsList().size() == 1) {
            paramBody.put("goodsAmount", (Double.parseDouble(price) * Double.parseDouble(orderNum)) + "");
        } else {
            paramBody.put("goodsAmount", price + "");
        }
        if (TextUtils.isEmpty(youhuiJuanID)) {
            paramBody.put("couponId", 0 + "");
        } else {
            paramBody.put("couponId", youhuiJuanID + "");
        }
        if (TextUtils.isEmpty(memberCardID)) {
            paramBody.put("serviceId", 0 + "");
        } else {
            paramBody.put("serviceId", memberCardID + "");
        }

        paramBody.put("shippingId", kuaidiWayId);
        paramBody.put("token", getSharedPreferencesUtil().getLogintoken());
        GetTotalAmountApi getTotalAmountApi = new GetTotalAmountApi((OrderConfirmActivity) context, simpleOnNextListenerGetTotalAmount);
        getTotalAmountApi.setCache(false);
        getTotalAmountApi.setMap(paramBody);
        if (TextUtils.isEmpty(skuStrDetail)) return;
        if (sureOrderBean != null && sureOrderBean.getGoodsList().size() == 1) {
            int skuId = sureOrderBean.getGoodsList().get(0).getSkuId();
            skuStrDetail = "{" + skuId + ":" + orderNum + "}";
        }
        getTotalAmountApi.setSkuStr(skuStrDetail);
        HttpManager.getInstance().doHttpDeal(getTotalAmountApi);
    }

    @Subscribe
    public void onEventShowThread(InformUpdate event) {
        if (event != null) {

            if (event.getEventType() == InformUpdate.KUAIDI_WAY_INFORM) {
                tvKuaidiWay.setText(event.getKuaidiWay());
                kuaidiWayId = event.getKuaidiWayId();

                //获取订单总金额
                getTotalAmount(kuaidiWayId, memberCardId, youhuiJuanId);
            } else if (event.getEventType() == InformUpdate.CLICK_DISCOUNT_INFORM) {
                youhuiJuanId = event.getYouhuiJuanId();
                //获取订单总金额
                getTotalAmount(kuaidiWayId, memberCardId, youhuiJuanId);
                if (discountList.size() > 0) {
                    tvDiscounts.setText("可用" + discountList.size() + "张，本次使用1张");
                    ll_discount_zekou.setVisibility(View.VISIBLE);
                }

                popupWindow.dismiss();
            } else if (event.getEventType() == InformUpdate.MORE_ASSRESS_INFORM) {
                ll_edit_address.setVisibility(View.VISIBLE);
                ll_add_address.setVisibility(View.GONE);
            } else if (event.getEventType() == InformUpdate.NO_ASSRESS_INFORM) {
                ll_edit_address.setVisibility(View.GONE);
                ll_add_address.setVisibility(View.VISIBLE);
            } else if (event.getEventType() == InformUpdate.HISTORY_FAPIAO_INFORM) {
                HistoryLookBean historyLookBean = event.getHistoryLookBean();

                String invPayee = historyLookBean.getInvPayee();
                Object companyAddress = historyLookBean.getCompanyAddress();
                Object blank = historyLookBean.getBlank();
                Object invPayeeNumber = historyLookBean.getInvPayeeNumber();
                et_company_name.setText(invPayee + "");
                et_address_or_phone.setText(companyAddress + "");
//                et_open_account_bank.setText(blank + "");
                et_tax_tel.setText(invPayeeNumber + "");
                et_bank_or_number.setText(blank + "");
                payeeId = historyLookBean.getPayeeId();

            }

        }
    }

    /**
     * 判断手机号是否符合规范
     *
     * @param phoneNo 输入的手机号
     * @return
     */
    public static boolean isPhoneNumber(String phoneNo) {
        if (TextUtils.isEmpty(phoneNo)) {
            return false;
        }
        if (phoneNo.length() == 11) {
            for (int i = 0; i < 11; i++) {
                if (!PhoneNumberUtils.isISODigit(phoneNo.charAt(i))) {
                    return false;
                }
            }
            Pattern p = Pattern.compile("^((13[^4,\\D])" + "|(134[^9,\\D])" +
                    "|(14[5,7])" +
                    "|(15[^4,\\D])" +
                    "|(17[3,6-8])" +
                    "|(18[0-9]))\\d{8}$");
            Matcher m = p.matcher(phoneNo);
            return m.matches();
        }
        return false;
    }

    //历史单位开票信息回调
    HttpOnNextListener simpleOnNextListener = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {

            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showToast(OrderConfirmActivity.this, subjects.getMsg());
                return;
            }
//            loading_layout.setStatus(LoadingLayout.SUCCESS);
            commonPop(inflateFaPiaoMessage);
            GetComanyInvoiceBean getComanyInvoiceBean = (GetComanyInvoiceBean) subjects.getData();

            if (dianZiFaPiaoBean != null) {
                et_company_name.setText(dealString(dianZiFaPiaoBean.getCompanyName() + ""));
                et_tax_tel.setText(dealString(dianZiFaPiaoBean.getDiscernNumber() + ""));
                et_address_or_phone.setText(dealString(dianZiFaPiaoBean.getAddressOrPhone() + ""));
                et_bank_or_number.setText(dealString(dianZiFaPiaoBean.getBankNumber() + ""));
                et_shoupiao_email.setText(dealString(dianZiFaPiaoBean.getEmail() + ""));
                et_shoupiao_phone.setText(dealString(dianZiFaPiaoBean.getPhoneTel()));
            } else {
                if (getComanyInvoiceBean != null) {
                    et_company_name.setText(dealString(getComanyInvoiceBean.getInvPayee() + ""));
                    et_tax_tel.setText(dealString(getComanyInvoiceBean.getInvPayeeNumber() + ""));
                    et_address_or_phone.setText(dealString(getComanyInvoiceBean.getCompanyAddress() + ""));
                    et_bank_or_number.setText(dealString(getComanyInvoiceBean.getBlank() + ""));
                    et_shoupiao_email.setText(dealString(getComanyInvoiceBean.getEmail() + ""));
                    et_shoupiao_phone.setText(dealString(getComanyInvoiceBean.getTel()));
                }
            }


        }


        @Override
        public void onCacheNext(String cache) {


        }


        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", e.getMessage());
//            if (e instanceof SocketTimeoutException || e instanceof ConnectException) {
//                loading_layout.setStatus(LoadingLayout.NO_NETWORK);
//            } else {
//                loading_layout.setStatus(LoadingLayout.ERROR);
//            }
        }
    };
    //增票资质信息回调
    HttpOnNextListener simpleOnNextListenerZengZhi = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {

            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showToast(OrderConfirmActivity.this, subjects.getMsg());
                return;
            }
            zengZhiShuiBean = (ZengZhiShuiBean) subjects.getData();

            if (zengZhiShuiBean != null) {
                setTICKET_ID(zengZhiShuiBean.getTicketId() + "");
                et_company_name_zengzhi.setText(dealString(zengZhiShuiBean.getCompanyName()));
                et_tax_tel_zengzhi.setText(dealString(zengZhiShuiBean.getIdentificationNumber() + ""));
                et_register_address_zengzhi.setText(dealString(zengZhiShuiBean.getRegAddress() + ""));
                et_register_phone_zengzhi.setText(dealString(zengZhiShuiBean.getRegMobile() + ""));
                et_open_account_bank.setText(dealString(zengZhiShuiBean.getBank()));
                et_bank_number_zengzhi.setText(dealString(zengZhiShuiBean.getBlankNo() + ""));

//                审核状态：0：待审核（审核中）1：审核通过2：审核不通过
                if (zengZhiShuiBean.getStatus() == 0) {
                    tv_type_hint.setText("平台将在您提交订单付款后对该发票信息进行审核。审核通过后，开具发票");
                    et_company_name_zengzhi.setFocusable(false);
                    et_tax_tel_zengzhi.setFocusable(false);
                    et_register_address_zengzhi.setFocusable(false);
                    et_register_phone_zengzhi.setFocusable(false);
                    et_open_account_bank.setFocusable(false);
                    et_bank_number_zengzhi.setFocusable(false);
                } else if (zengZhiShuiBean.getStatus() == 1) {
                    tv_type_hint.setText("融融网依法开具发票，请按照税法规定使用发票。增值税专用发票只支持纸型邮寄");
                    et_company_name_zengzhi.setFocusable(false);
                    et_tax_tel_zengzhi.setFocusable(false);
                    et_register_address_zengzhi.setFocusable(false);
                    et_register_phone_zengzhi.setFocusable(false);
                    et_open_account_bank.setFocusable(false);
                    et_bank_number_zengzhi.setFocusable(false);
                } else if (zengZhiShuiBean.getStatus() == 2) {
                    tv_type_hint.setText("您的增票资质审核不通过，请在我的-增票资质进行查看");
                    et_company_name_zengzhi.setFocusable(false);
                    et_tax_tel_zengzhi.setFocusable(false);
                    et_register_address_zengzhi.setFocusable(false);
                    et_register_phone_zengzhi.setFocusable(false);
                    et_open_account_bank.setFocusable(false);
                    et_bank_number_zengzhi.setFocusable(false);
                } else {
                    tv_type_hint.setText("平台将在您提交订单付款后对该发票信息进行审核。审核通过后，开具发票");
                    et_company_name_zengzhi.setFocusable(true);
                    et_tax_tel_zengzhi.setFocusable(true);
                    et_register_address_zengzhi.setFocusable(true);
                    et_register_phone_zengzhi.setFocusable(true);
                    et_open_account_bank.setFocusable(true);
                    et_bank_number_zengzhi.setFocusable(true);
                }
            } else {
                tv_type_hint.setText("平台将在您提交订单付款后对该发票信息进行审核。审核通过后，开具发票");
            }

        }


        @Override
        public void onCacheNext(String cache) {


        }


        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", e.getMessage());
        }
    };
    //增票资质信息回调
    HttpOnNextListener simpleOnNextListenerAddOrUpdateZengZhi = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {

            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {

                if (subjects.getCode().equals("1002")) {
                    popupWindow.dismiss();
                } else {
                    ToastTools.showToast(OrderConfirmActivity.this, subjects.getMsg());
                }
                return;
            }
//            Integer fapiaoID = Integer.valueOf(String.valueOf(subjects.getData()));
            double fapiaoID = Double.parseDouble(subjects.getData() + "");
            int num = (new Double(fapiaoID)).intValue();
            setTICKET_ID(num + "");
            faPiaoShow();
            popupWindow.dismiss();

        }


        @Override
        public void onCacheNext(String cache) {


        }


        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", e.getMessage());
        }
    };

    //订单商品列表回调
    HttpOnNextListener simpleOnNextListenerConfirmOrder = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {
            goodsList.clear();
            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showToast(OrderConfirmActivity.this, subjects.getMsg());
                return;
            }
//            loading_layout.setStatus(LoadingLayout.SUCCESS);

            if ((SureOrderBean) subjects.getData() != null) {
                sureOrderBean = (SureOrderBean) subjects.getData();
                SureOrderBean.DefaultAddressBean defaultAddress = sureOrderBean.getDefaultAddress();
                if (defaultAddress != null) {


                    tvUserName.setText(defaultAddress.getConsignee());
                    tvAddressPhone.setText(defaultAddress.getTel() + "");
                    tvAddressName.setText(defaultAddress.getProvinceName() + defaultAddress.getCityName() + defaultAddress.getAddress());
                    addressId = defaultAddress.getAddressId();


                    tv_bottom_address.setText(defaultAddress.getProvinceName() + defaultAddress.getCityName() + defaultAddress.getAddress() + "");
                    tv_bottom_address.setVisibility(View.VISIBLE);
                    ll_edit_address.setVisibility(View.VISIBLE);
                    ll_add_address.setVisibility(View.GONE);

                } else {
                    tv_bottom_address.setVisibility(View.GONE);
                    ll_edit_address.setVisibility(View.GONE);
                    ll_add_address.setVisibility(View.VISIBLE);
                }
                goodsList.addAll(sureOrderBean.getGoodsList());

                moreProductsListAdapter.notifyDataSetChanged();

                //商品金额
                tvGoodAllprice.setText("¥" + dealNumber(sureOrderBean.getGoodsAmount() + ""));
                //没有优惠券不显示
                if (sureOrderBean.getCouponNum() > 0) {
                    tvDiscounts.setText("可用" + sureOrderBean.getCouponNum() + "张，本次使用0张");
                    llDiscounts.setVisibility(View.VISIBLE);


                } else {
                    llDiscounts.setVisibility(View.GONE);

                }
                //只有商品为下载使用的商品才显示提示
                if (sureOrderBean.getOrderType() == 1 && sureOrderBean.getGoodsList().size() > 0) {
                    if (sureOrderBean.getGoodsList().get(0).getIsReal() == 0) {
                        tv_download_goods_hint.setVisibility(View.VISIBLE);
                    } else {
                        tv_download_goods_hint.setVisibility(View.GONE);
                    }

                }
                moreProductsListAdapter.setMoreOrderType(sureOrderBean.getOrderType());
                moreProductsListAdapter.setMoreBiaoZhunImg(sureOrderBean.getBiaoZhunImg());
                if (goodsList.size() == 1) {
                    goodsListBean = goodsList.get(0);


                    if (sureOrderBean.getOrderType() == 4) {
                        if (!TextUtils.isEmpty(goodsListBean.getGoodsImg())) {
                            if (goodsListBean.getGoodsImg().contains("rongrong.")) {
                                GlideUtils.loaderImage(OrderConfirmActivity.this, goodsListBean.getGoodsImg(), ivAloneGoodPic);
                            } else {
                                GlideUtils.loaderImage(OrderConfirmActivity.this, sureOrderBean.getBiaoZhunImg() + goodsListBean.getGoodsImg(), ivAloneGoodPic);
                            }
                            ivAloneGoodPic.setVisibility(View.VISIBLE);
                            llPicTag.setVisibility(View.GONE);
                        } else {
                            String keywords = goodsListBean.getKeywords();
                            String catName = goodsListBean.getCatName();
                            tvGoodsTel.setText(keywords);
                            tvGoodsType.setText(catName);
                            llPicTag.setVisibility(View.VISIBLE);
                            ivAloneGoodPic.setVisibility(View.VISIBLE);
                            Glide.with(OrderConfirmActivity.this).load(R.mipmap.common_bg).into(ivAloneGoodPic);
                        }
                    } else {
                        if (!TextUtils.isEmpty(goodsListBean.getGoodsImg())) {
                            GlideUtils.loaderImage(OrderConfirmActivity.this, goodsListBean.getGoodsImg(), ivAloneGoodPic);
                            ivAloneGoodPic.setVisibility(View.VISIBLE);
                            llPicTag.setVisibility(View.GONE);
                        } else {
                            //默认图
//                GlideUtils.loaderImage(context, R.mipmap.common_bg, iv_goods_pic);
                            String keywords = goodsListBean.getKeywords();
                            String catName = goodsListBean.getCatName();
                            tvGoodsTel.setText(keywords);
                            tvGoodsType.setText(catName);
                            Glide.with(OrderConfirmActivity.this).load(R.mipmap.common_bg).into(ivAloneGoodPic);
                            ivAloneGoodPic.setVisibility(View.VISIBLE);
                            llPicTag.setVisibility(View.VISIBLE);
                        }

                    }


                    tvAloneGoodName.setText(goodsListBean.getKeywords() + "  " + goodsListBean.getGoodsName());
                    tvAloneGoodPrice.setText("¥" + goodsListBean.getRealPrice());
                    tvAloneGoodNum.setText("x" + goodsListBean.getGoodsNumber());
                    payOrderNum.setText(goodsListBean.getGoodsNumber() + "");
                    num = goodsListBean.getGoodsNumber();
                    tvAloneGoodSubtitle.setText(goodsListBean.getSkuName());
                    tvOrderPrice.setMoneyText("" + MoneyShowUtils.changTVsize(MoneyShowUtils.dealNumber(goodsListBean.getRealPrice() + "")));

                    if (!TextUtils.isEmpty(goodsListBean.getAttrShow())) {
                        tvStatus.setText(goodsListBean.getAttrShow());
                        tvStatus.setVisibility(View.VISIBLE);
                    }


                    llGoods.setVisibility(View.VISIBLE);
                    llMoreProducts.setVisibility(View.GONE);
                    ll_goods_num.setVisibility(View.VISIBLE);
                } else if (goodsList.size() > 1) {
                    if (goodsList.size() == 2) {
                        SureOrderBean.GoodsListBean goodsListBean = goodsList.get(0);
                       /* if (sureOrderBean.getOrderType()==4){
                            if (goodsListBean.getGoodsImg()!=null){
                                if (itemsViewBean.getGoodsImg().contains("rongrong.")){
                                    GlideUtils.loaderImage(context, goodsListBean.getGoodsImg(), iv_goods_pic);
                                }else {
                                    GlideUtils.loaderImage(context,biaoZhunImg+goodsListBean.getGoodsImg(), iv_goods_pic);
                                }
                                iv_goods_pic.setVisibility(View.VISIBLE);
                                tv_goods_pic.setVisibility(View.GONE);
                            }else {
                                String keywords = itemsViewBean.getKeywords();
                                tv_goods_pic.setText(keywords);
                                tv_goods_pic.setVisibility(View.VISIBLE);
                                iv_goods_pic.setVisibility(View.GONE);
                            }
                        }else {
                            if (itemsViewBean.getGoodsImg()!=null){
                                GlideUtils.loaderImage(context, goodsListBean.getGoodsImg(), iv_goods_pic);
                            }else {
                                //默认图
                                GlideUtils.loaderImage(context, itemsViewBean.getGoodsImg(), iv_goods_pic);
                            }
                            iv_goods_pic.setVisibility(View.VISIBLE);
                            tv_goods_pic.setVisibility(View.GONE);
                        }*/


                        if (sureOrderBean.getOrderType() == 4) {
                            if (!TextUtils.isEmpty(goodsListBean.getGoodsImg())) {
                                if (goodsListBean.getGoodsImg().contains("rongrong.")) {
                                    GlideUtils.loaderImage(context, goodsListBean.getGoodsImg(), ivProductOne);
                                } else {
                                    GlideUtils.loaderImage(context, sureOrderBean.getBiaoZhunImg() + goodsListBean.getGoodsImg(), ivProductOne);
                                }
                                ivProductOne.setVisibility(View.VISIBLE);
                                llPicTagOne.setVisibility(View.GONE);
                            } else {
                                String keywords = goodsListBean.getKeywords();
                                String catName = goodsListBean.getCatName();
                                tvGoodsTypeOne.setText(catName);
                                tvGoodsTelOne.setText(keywords);
                                llPicTagOne.setVisibility(View.VISIBLE);
                                ivProductOne.setVisibility(View.VISIBLE);
                                Glide.with(context).load(R.mipmap.common_bg).into(ivProductOne);
                            }
                        } else {
                            if (!TextUtils.isEmpty(goodsListBean.getGoodsImg())) {
                                GlideUtils.loaderImage(context, goodsListBean.getGoodsImg(), ivProductOne);
                                ivProductOne.setVisibility(View.VISIBLE);
                                llPicTagOne.setVisibility(View.GONE);
                            } else {
                                //默认图
//                GlideUtils.loaderImage(context, R.mipmap.common_bg, iv_goods_pic);
                                String keywords = goodsListBean.getKeywords();
                                String catName = goodsListBean.getCatName();
                                tvGoodsTypeOne.setText(catName);
                                tvGoodsTelOne.setText(keywords);
                                Glide.with(context).load(R.mipmap.common_bg).into(ivProductOne);
                                ivProductOne.setVisibility(View.VISIBLE);
                                llPicTagOne.setVisibility(View.VISIBLE);
                            }

                        }

                        if (!TextUtils.isEmpty(goodsListBean.getAttrShow())) {
                            tvStatusOne.setText(goodsListBean.getAttrShow());
                            tvStatusOne.setVisibility(View.VISIBLE);
                        }
//                        GlideUtils.loaderImage(OrderConfirmActivity.this, goodsListBean.getGoodsImg(), ivProductOne);
                        tvProductOneNumber.setText("x" + goodsListBean.getGoodsNumber());
                        SureOrderBean.GoodsListBean goodsListBeanTwo = goodsList.get(1);


                        if (sureOrderBean.getOrderType() == 4) {
                            if (!TextUtils.isEmpty(goodsListBeanTwo.getGoodsImg())) {
                                if (goodsListBeanTwo.getGoodsImg().contains("rongrong.")) {
                                    GlideUtils.loaderImage(context, goodsListBeanTwo.getGoodsImg(), ivProductTwo);
                                } else {
                                    GlideUtils.loaderImage(context, sureOrderBean.getBiaoZhunImg() + goodsListBeanTwo.getGoodsImg(), ivProductTwo);
                                }
                                ivProductTwo.setVisibility(View.VISIBLE);
                                llPicTagTwo.setVisibility(View.GONE);
                            } else {
                                String keywords = goodsListBeanTwo.getKeywords();
                                String catName = goodsListBeanTwo.getCatName();
                                tvGoodsTypeTwo.setText(catName);
                                tvGoodsTelTwo.setText(keywords);
                                llPicTagTwo.setVisibility(View.VISIBLE);
                                ivProductTwo.setVisibility(View.VISIBLE);
                                Glide.with(context).load(R.mipmap.common_bg).into(ivProductTwo);
                            }
                        } else {
                            if (!TextUtils.isEmpty(goodsListBeanTwo.getGoodsImg())) {
                                GlideUtils.loaderImage(context, goodsListBeanTwo.getGoodsImg(), ivProductTwo);
                                ivProductTwo.setVisibility(View.VISIBLE);
                                llPicTagTwo.setVisibility(View.GONE);
                            } else {
                                //默认图
//                GlideUtils.loaderImage(context, R.mipmap.common_bg, iv_goods_pic);
                                String keywords = goodsListBeanTwo.getKeywords();
                                String catName = goodsListBeanTwo.getCatName();
                                tvGoodsTypeTwo.setText(catName);
                                tvGoodsTelTwo.setText(keywords);
                                Glide.with(context).load(R.mipmap.common_bg).into(ivProductTwo);
                                ivProductTwo.setVisibility(View.VISIBLE);
                                llPicTagTwo.setVisibility(View.VISIBLE);
                            }

                        }

                        if (!TextUtils.isEmpty(goodsListBeanTwo.getAttrShow())) {
                            tvStatusTwo.setText(goodsListBeanTwo.getAttrShow());
                            tvStatusTwo.setVisibility(View.VISIBLE);
                        }
//                        GlideUtils.loaderImage(OrderConfirmActivity.this, goodsListBeanTwo.getGoodsImg(), ivProductTwo);
                        tvProductTwoNumber.setText("x" + goodsListBeanTwo.getGoodsNumber());
                        tvAloneGoodPrice.setText("¥" + sureOrderBean.getGoodsAmount());
                        rlGoodsThree.setVisibility(View.INVISIBLE);

                    } else if (goodsList.size() >= 3) {
                        SureOrderBean.GoodsListBean goodsListBean = goodsList.get(0);

                        if (sureOrderBean.getOrderType() == 4) {
                            if (!TextUtils.isEmpty(goodsListBean.getGoodsImg())) {
                                if (goodsListBean.getGoodsImg().contains("rongrong.")) {
                                    GlideUtils.loaderImage(context, goodsListBean.getGoodsImg(), ivProductOne);
                                } else {
                                    GlideUtils.loaderImage(context, sureOrderBean.getBiaoZhunImg() + goodsListBean.getGoodsImg(), ivProductOne);
                                }
                                ivProductOne.setVisibility(View.VISIBLE);
                                llPicTagOne.setVisibility(View.GONE);
                            } else {
                                String keywords = goodsListBean.getKeywords();
                                String catName = goodsListBean.getCatName();
                                tvGoodsTypeOne.setText(catName);
                                tvGoodsTelOne.setText(keywords);
                                llPicTagOne.setVisibility(View.VISIBLE);
                                ivProductOne.setVisibility(View.VISIBLE);
                                Glide.with(context).load(R.mipmap.common_bg).into(ivProductOne);
                            }
                        } else {
                            if (!TextUtils.isEmpty(goodsListBean.getGoodsImg())) {
                                GlideUtils.loaderImage(context, goodsListBean.getGoodsImg(), ivProductOne);
                                ivProductOne.setVisibility(View.VISIBLE);
                                ivProductOne.setVisibility(View.GONE);
                            } else {
                                //默认图
//                GlideUtils.loaderImage(context, R.mipmap.common_bg, iv_goods_pic);
                                String keywords = goodsListBean.getKeywords();
                                String catName = goodsListBean.getCatName();
                                tvGoodsTypeOne.setText(catName);
                                tvGoodsTelOne.setText(keywords);
                                Glide.with(context).load(R.mipmap.common_bg).into(ivProductOne);
                                ivProductOne.setVisibility(View.VISIBLE);
                                ivProductOne.setVisibility(View.VISIBLE);
                            }

                        }
                        if (!TextUtils.isEmpty(goodsListBean.getAttrShow())) {
                            tvStatusOne.setText(goodsListBean.getAttrShow());
                            tvStatusOne.setVisibility(View.VISIBLE);
                        }
//                        GlideUtils.loaderImage(OrderConfirmActivity.this, goodsListBean.getGoodsImg(), ivProductOne);
                        tvProductOneNumber.setText("x" + goodsListBean.getGoodsNumber());
                        SureOrderBean.GoodsListBean goodsListBeanTwo = goodsList.get(1);


                        if (sureOrderBean.getOrderType() == 4) {
                            if (!TextUtils.isEmpty(goodsListBeanTwo.getGoodsImg())) {
                                if (goodsListBeanTwo.getGoodsImg().contains("rongrong.")) {
                                    GlideUtils.loaderImage(context, goodsListBeanTwo.getGoodsImg(), ivProductTwo);
                                } else {
                                    GlideUtils.loaderImage(context, sureOrderBean.getBiaoZhunImg() + goodsListBeanTwo.getGoodsImg(), ivProductTwo);
                                }
                                ivProductTwo.setVisibility(View.VISIBLE);
                                llPicTagTwo.setVisibility(View.GONE);
                            } else {
                                String keywords = goodsListBeanTwo.getKeywords();
                                String catName = goodsListBeanTwo.getCatName();
                                tvGoodsTypeTwo.setText(catName);
                                tvGoodsTelTwo.setText(keywords);
                                llPicTagTwo.setVisibility(View.VISIBLE);
                                ivProductTwo.setVisibility(View.VISIBLE);
                                Glide.with(context).load(R.mipmap.common_bg).into(ivProductTwo);
                            }
                        } else {
                            if (!TextUtils.isEmpty(goodsListBeanTwo.getGoodsImg())) {
                                GlideUtils.loaderImage(context, goodsListBeanTwo.getGoodsImg(), ivProductTwo);
                                ivProductTwo.setVisibility(View.VISIBLE);
                                llPicTagTwo.setVisibility(View.GONE);
                            } else {
                                //默认图
//                GlideUtils.loaderImage(context, R.mipmap.common_bg, iv_goods_pic);
                                String keywords = goodsListBeanTwo.getKeywords();
                                String catName = goodsListBeanTwo.getCatName();
                                tvGoodsTypeTwo.setText(catName);
                                tvGoodsTelTwo.setText(keywords);
                                Glide.with(context).load(R.mipmap.common_bg).into(ivProductTwo);
                                ivProductTwo.setVisibility(View.VISIBLE);
                                llPicTagTwo.setVisibility(View.VISIBLE);
                            }

                        }
                        if (!TextUtils.isEmpty(goodsListBeanTwo.getAttrShow())) {
                            tvStatusTwo.setText(goodsListBeanTwo.getAttrShow());
                            tvStatusTwo.setVisibility(View.VISIBLE);
                        }
//                        GlideUtils.loaderImage(OrderConfirmActivity.this, goodsListBeanTwo.getGoodsImg(), ivProductTwo);
                        tvProductTwoNumber.setText("x" + goodsListBeanTwo.getGoodsNumber());
                        SureOrderBean.GoodsListBean goodsListBeanThree = goodsList.get(2);


                        if (sureOrderBean.getOrderType() == 4) {
                            if (!TextUtils.isEmpty(goodsListBeanThree.getGoodsImg())) {
                                if (goodsListBeanThree.getGoodsImg().contains("rongrong.")) {
                                    GlideUtils.loaderImage(context, goodsListBeanThree.getGoodsImg(), ivProductThree);
                                } else {
                                    GlideUtils.loaderImage(context, sureOrderBean.getBiaoZhunImg() + goodsListBeanThree.getGoodsImg(), ivProductThree);
                                }
                                ivProductThree.setVisibility(View.VISIBLE);
                                llPicTagThree.setVisibility(View.GONE);
                            } else {
                                String keywords = goodsListBeanThree.getKeywords();
                                String catName = goodsListBeanThree.getCatName();
                                tvGoodsTypeThree.setText(catName);
                                tvGoodsTelThree.setText(keywords);
                                llPicTagThree.setVisibility(View.VISIBLE);
                                ivProductThree.setVisibility(View.VISIBLE);
                                Glide.with(context).load(R.mipmap.common_bg).into(ivProductThree);
                            }
                        } else {
                            if (!TextUtils.isEmpty(goodsListBeanThree.getGoodsImg())) {
                                GlideUtils.loaderImage(context, goodsListBeanThree.getGoodsImg(), ivProductThree);
                                ivProductThree.setVisibility(View.VISIBLE);
                                llPicTagThree.setVisibility(View.GONE);
                            } else {
                                //默认图
//                GlideUtils.loaderImage(context, R.mipmap.common_bg, iv_goods_pic);
                                String keywords = goodsListBeanThree.getKeywords();
                                String catName = goodsListBeanThree.getCatName();
                                tvGoodsTypeThree.setText(catName);
                                tvGoodsTelThree.setText(keywords);
                                Glide.with(context).load(R.mipmap.common_bg).into(ivProductThree);
                                ivProductThree.setVisibility(View.VISIBLE);
                                llPicTagThree.setVisibility(View.VISIBLE);
                            }

                        }

                        if (!TextUtils.isEmpty(goodsListBeanThree.getAttrShow())) {
                            tvStatusThree.setText(goodsListBeanThree.getAttrShow());
                            tvStatusThree.setVisibility(View.VISIBLE);
                        }
//                        GlideUtils.loaderImage(OrderConfirmActivity.this, goodsListBeanThree.getGoodsImg(), ivProductThree);
                        tvProductThreeNumber.setText("x" + goodsListBeanThree.getGoodsNumber());
                        tvAloneGoodPrice.setText("¥" + sureOrderBean.getGoodsAmount());
                    }
                    tv_goods_num_pop.setText("共" + sureOrderBean.getGoodsNumber() + "件");
                    tvGoodsNum.setText("共" + sureOrderBean.getGoodsNumber() + "件");
                    llGoods.setVisibility(View.GONE);
                    llMoreProducts.setVisibility(View.VISIBLE);
                }
                //2：增值税专用发票  3 : 电子发票

                //1：个人  2：单位
                if (sureOrderBean.getHistoryInvoice() != null) {
                    historyInvoice = sureOrderBean.getHistoryInvoice();

                   /* if (historyInvoice.getInvPayeeType() == 1) {
                        if (historyInvoice.getInvType() == 2) {
                            tvFapiaoType.setText("增值税专用(商品明细-");
                            tv_unit_name.setText("个人");
                            tv_unit_name.setTextColor(getResources().getColor(R.color.base_subtitle_color));
                            tv_dianzi_fapiao.setSelected(false);
                            tv_zengzhi_fapiao.setSelected(true);
                            DIANZI_OR_ZENGZHI = 2;
                        } else if (historyInvoice.getInvType() == 3) {
                            tvFapiaoType.setText("电子(商品明细-");
                            tv_unit_name.setText("个人");
                            tv_unit_name.setTextColor(getResources().getColor(R.color.base_subtitle_color));
                            tv_dianzi_fapiao.setSelected(true);
                            tv_zengzhi_fapiao.setSelected(false);
                            DIANZI_OR_ZENGZHI = 3;
                        }
                        tv_unit.setSelected(false);
                        tv_personal.setSelected(true);
                        UNIT_OR_PERSON = 1;
                    } else if (historyInvoice.getInvPayeeType() == 2) {
                        tvFapiaoType.setText("电子(商品明细-");
                        tv_unit_name.setText(historyInvoice.getInvPayee() + "");
                        tv_unit_name.setTextColor(getResources().getColor(R.color.base_subtitle_color));
                        if (historyInvoice.getInvType() == 2) {
                            tvFapiaoType.setText("增值税专用(商品明细-");
                            tv_unit_name.setText(historyInvoice.getInvPayee() + "");
                            tv_unit_name.setTextColor(getResources().getColor(R.color.base_subtitle_color));
                            tv_dianzi_fapiao.setSelected(false);
                            tv_zengzhi_fapiao.setSelected(true);
                            DIANZI_OR_ZENGZHI = 2;
                        } else if (historyInvoice.getInvType() == 3) {
                            tvFapiaoType.setText("电子(商品明细-");
                            tv_unit_name.setText(historyInvoice.getInvPayee() + "");
                            tv_unit_name.setTextColor(getResources().getColor(R.color.base_subtitle_color));
                            tv_dianzi_fapiao.setSelected(true);
                            tv_zengzhi_fapiao.setSelected(false);
                            DIANZI_OR_ZENGZHI = 3;
                        }
                        tv_unit.setSelected(true);
                        tv_personal.setSelected(false);
                        UNIT_OR_PERSON = 2;
                    } else {
                        if (historyInvoice.getInvType() == 2) {
                            tvFapiaoType.setText("增值税专用(商品明细-");
                            tv_unit_name.setText("请输入单位名称");
                            tv_dianzi_fapiao.setSelected(false);
                            tv_zengzhi_fapiao.setSelected(true);
                        } else if (historyInvoice.getInvType() == 3) {
                            tvFapiaoType.setText("电子(商品明细-");
                            tv_unit_name.setText("请输入单位名称");
                            tv_dianzi_fapiao.setSelected(true);
                            tv_zengzhi_fapiao.setSelected(false);
                        }
                    }*/
                    //2：增值税专用发票  3 : 电子发票

                    //1：个人  2：单位
                    if (historyInvoice.getInvType() == 2) {
                        tvFapiaoType.setText("增值税专用(商品明细-");
                        tv_unit_name.setText(historyInvoice.getInvPayee() + "");
                        tv_unit_name.setTextColor(getResources().getColor(R.color.base_subtitle_color));
                        tv_dianzi_fapiao.setSelected(false);
                        tv_zengzhi_fapiao.setSelected(true);
                        tv_dianzi_fapiao.setTextColor(getResources().getColor(R.color.base_title_color));
                        tv_zengzhi_fapiao.setTextColor(getResources().getColor(R.color.color_99C729));

                        DIANZI_OR_ZENGZHI = 2;

                        ll_dianzi_fapiao.setVisibility(View.GONE);
                        ll_zengzhi_fapiao.setVisibility(View.VISIBLE);

                        //增票资质信息请求
                        ZengZhiShuiApi zengZhiShuiApi = new ZengZhiShuiApi(OrderConfirmActivity.this, simpleOnNextListenerZengZhi);
                        zengZhiShuiApi.setCache(false);
                        HttpManager.getInstance().doHttpDeal(zengZhiShuiApi);

                    } else if (historyInvoice.getInvType() == 3) {
                        if (historyInvoice.getInvPayeeType() == 1) {

                            tvFapiaoType.setText("电子(商品明细-");
                            tv_unit_name.setText("个人");
                            tv_unit_name.setTextColor(getResources().getColor(R.color.base_subtitle_color));
                            UNIT_OR_PERSON = 1;
                        } else if (historyInvoice.getInvPayeeType() == 2) {
                            tvFapiaoType.setText("电子(商品明细-");
                            tv_unit_name.setText(historyInvoice.getInvPayee() + "");
                            tv_unit_name.setTextColor(getResources().getColor(R.color.base_subtitle_color));
                            UNIT_OR_PERSON = 2;
                        }
                        tv_dianzi_fapiao.setSelected(true);
                        tv_zengzhi_fapiao.setSelected(false);
                        tv_dianzi_fapiao.setTextColor(getResources().getColor(R.color.color_99C729));
                        tv_zengzhi_fapiao.setTextColor(getResources().getColor(R.color.base_title_color));

                        DIANZI_OR_ZENGZHI = 3;
                    } else {
                        if (historyInvoice.getInvType() == 2) {
                            tvFapiaoType.setText("增值税专用(商品明细-");
                            tv_unit_name.setText("请输入单位名称");
                            tv_dianzi_fapiao.setSelected(false);
                            tv_zengzhi_fapiao.setSelected(true);
                            tv_dianzi_fapiao.setTextColor(getResources().getColor(R.color.base_title_color));
                            tv_zengzhi_fapiao.setTextColor(getResources().getColor(R.color.color_99C729));
                        } else if (historyInvoice.getInvType() == 3) {
                            tvFapiaoType.setText("电子(商品明细-");
                            tv_unit_name.setText("请输入单位名称");
                            tv_dianzi_fapiao.setSelected(true);
                            tv_zengzhi_fapiao.setSelected(false);
                            tv_dianzi_fapiao.setTextColor(getResources().getColor(R.color.color_99C729));
                            tv_zengzhi_fapiao.setTextColor(getResources().getColor(R.color.base_title_color));
                        }
                    }
                    et_company_name.setText(dealString(historyInvoice.getInvPayee()));
                    et_shoupiao_phone.setText(dealString(historyInvoice.getTel()));
                }

                if (sureOrderBean.getShippingList() != null && sureOrderBean.getShippingList().size() > 0) {
                    SureOrderBean.ShippingListBean shippingListBean = sureOrderBean.getShippingList().get(0);
                    tvKuaidiWay.setText(shippingListBean.getShippingName());
                    kuaidiWayId = shippingListBean.getShippingId() + "";
                    if (!tvKuaidiWay.getText().toString().trim().isEmpty()) {
                        kuaiDiWayListAdapter.setSelectWay(tvKuaidiWay.getText().toString().trim());
                        kuaiDiWayListAdapter.notifyDataSetChanged();
                    }
                }


                if (sureOrderBean.getVipService() != null && sureOrderBean.getVipService().size() > 0) {
                    vipServiceBean = sureOrderBean.getVipService().get(0);
                    memberCardYuE = vipServiceBean.getBalance() + "";
                    memberCardId = vipServiceBean.getServiceId() + "";
                    if (getTotalAmountBean != null) {
                        tv_member_card_dikou.setText("余额¥" + MoneyShowUtils.dealNumber((vipServiceBean.getBalance() - getTotalAmountBean.getDeduction()) + "") + ", 已抵扣¥" + getTotalAmountBean.getDeduction());
                    }
                    memberCardListAdapter.setMemberID(memberCardId);
                    if (memberCardYuE != null) {
                        memberCardListAdapter.setMemberCardSelect(memberCardYuE);
                    }
                    memberCardListAdapter.notifyDataSetChanged();
                    ll_member_zhekou.setVisibility(View.VISIBLE);
                    tv_no_member_card.setVisibility(View.GONE);
                    tv_member_configm_btn.setVisibility(View.VISIBLE);
                    llMemberCard.setVisibility(View.VISIBLE);
                } else {
                    ll_member_zhekou.setVisibility(View.VISIBLE);
                    tv_member_card_dikou.setText("暂无可用会员卡");
                    tv_no_member_card.setVisibility(View.VISIBLE);
                    tv_member_configm_btn.setVisibility(View.GONE);
                    llMemberCard.setVisibility(View.GONE);
                }
                skuStrDetail = sureOrderBean.getSkuStr();

                getTotalAmount(kuaidiWayId, memberCardId, youhuiJuanId);

                if (sureOrderBean != null) {
                    if (sureOrderBean.getOrderType() == 4 || sureOrderBean.getOrderType() == 6 || sureOrderBean.getOrderType() == 8) {
                        tvFapiaoType.setText("电子(商品明细-");
                        DIANZI_OR_ZENGZHI = 3;
                    }
                }


            }

        }


        @Override
        public void onCacheNext(String cache) {


        }


        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", e.getMessage());
//            if (e instanceof SocketTimeoutException || e instanceof ConnectException) {
//                loading_layout.setStatus(LoadingLayout.NO_NETWORK);
//            } else {
//                loading_layout.setStatus(LoadingLayout.ERROR);
//            }
        }
    };


    //配送方式列表
    HttpOnNextListener simpleOnNextListenerShipWay = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {
            shipList.clear();
            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showToast(OrderConfirmActivity.this, subjects.getMsg());
                return;
            }
//            loading_layout.setStatus(LoadingLayout.SUCCESS);
            commonPop(inflateKuaiDiWay);
            ArrayList<ShippingListBean> data = (ArrayList<ShippingListBean>) subjects.getData();
            shipList.addAll(data);
            kuaiDiWayListAdapter.notifyDataSetChanged();
        }


        @Override
        public void onCacheNext(String cache) {


        }


        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", e.getMessage());
//            if (e instanceof SocketTimeoutException || e instanceof ConnectException) {
//                loading_layout.setStatus(LoadingLayout.NO_NETWORK);
//            } else {
//                loading_layout.setStatus(LoadingLayout.ERROR);
//            }
        }
    };

    //会员卡列表
    HttpOnNextListener simpleOnNextListenerMemberCard = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {
            memberCardList.clear();
            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showToast(OrderConfirmActivity.this, subjects.getMsg());
                return;
            }
//            loading_layout.setStatus(LoadingLayout.SUCCESS);
            ArrayList<MemberCardBean> memberList = (ArrayList<MemberCardBean>) subjects.getResult();
            if (memberList != null) {
                if (memberList.size() > 0) {
                    tv_no_member_card.setVisibility(View.GONE);
                    tv_member_configm_btn.setVisibility(View.VISIBLE);

                    commonPop(inflateMemberCard);
                    memberList.get(0).setSelect(true);
                    memberCardListAdapter.setmSelectedPos(0);
                    memberCardList.addAll(memberList);
                    memberCardListAdapter.notifyDataSetChanged();
                } else {
                    ToastTools.showToast(OrderConfirmActivity.this, "您当前没有会员卡");
                }
            } else {
                commonPop(inflateMemberCard);
                tv_no_member_card.setVisibility(View.VISIBLE);
                tv_member_configm_btn.setVisibility(View.GONE);
                llMemberCard.setVisibility(View.GONE);
            }


        }


        @Override
        public void onCacheNext(String cache) {


        }


        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", e.getMessage());
//            if (e instanceof SocketTimeoutException || e instanceof ConnectException) {
//                loading_layout.setStatus(LoadingLayout.NO_NETWORK);
//            } else {
//                loading_layout.setStatus(LoadingLayout.ERROR);
//            }
        }
    };


    //获取订单总金额
    HttpOnNextListener simpleOnNextListenerGetTotalAmount = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {
            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showToast(context, subjects.getMsg());
                return;
            }
            if ((GetTotalAmountBean) subjects.getData() != null) {
                getTotalAmountBean = (GetTotalAmountBean) subjects.getData();
//                tvGoodAllprice.setText("¥" + getTotalAmountBean.getTotalAmount());
                if (getTotalAmountBean != null && vipServiceBean != null && getTotalAmountBean.getDeduction() > 0) {
                    tv_member_card_dikou.setText("余额¥" + MoneyShowUtils.dealNumber((vipServiceBean.getBalance() - getTotalAmountBean.getDeduction()) + "") + ", 已抵扣¥" + getTotalAmountBean.getDeduction());
                    llMemberCard.setVisibility(View.VISIBLE);
                } else if (getTotalAmountBean != null && TextUtils.isEmpty(memberCardId) && getTotalAmountBean.getDeduction() <= 0) {
                    if (sureOrderBean.getVipService() != null && sureOrderBean.getVipService().size() > 0) {
                        ((OrderConfirmActivity) context).tv_member_card_dikou.setText("请选择会员卡");
                    } else {
                        ((OrderConfirmActivity) context).tv_member_card_dikou.setText("暂无可用会员卡");
                    }
                    llMemberCard.setVisibility(View.GONE);
                } else if (!TextUtils.isEmpty(memberCardId) && !TextUtils.isEmpty(youhuiJuanId) && getTotalAmountBean.getRange() > 0 && getTotalAmountBean.getDeduction() <= 0 && getTotalAmountBean.getTotalAmount() <= 0) {
                    tv_member_card_dikou.setText("余额¥" + MoneyShowUtils.dealNumber((vipServiceBean.getBalance()) + "") + ", 已抵扣¥" + MoneyShowUtils.dealNumber(0.00 + ""));
                    llMemberCard.setVisibility(View.GONE);
                } else if (!TextUtils.isEmpty(memberCardId) && !TextUtils.isEmpty(youhuiJuanId) && getTotalAmountBean.getRange() > 0 && getTotalAmountBean.getDeduction() > 0) {
                    tv_member_card_dikou.setText("余额¥" + MoneyShowUtils.dealNumber((vipServiceBean.getBalance() - getTotalAmountBean.getDeduction()) + "") + ", 已抵扣¥" + getTotalAmountBean.getDeduction());
                    llMemberCard.setVisibility(View.VISIBLE);
                } else if (!TextUtils.isEmpty(memberCardId) && TextUtils.isEmpty(youhuiJuanId)) {
                    tv_member_card_dikou.setText("余额¥" + MoneyShowUtils.dealNumber((vipServiceBean.getBalance() - getTotalAmountBean.getDeduction()) + "") + ", 已抵扣¥" + getTotalAmountBean.getDeduction());
                    llMemberCard.setVisibility(View.VISIBLE);
                }







               /* else if (getTotalAmountBean.getRange()>0&&getTotalAmountBean.getTotalAmount()<0){
                    tv_member_card_dikou.setText("余额¥" + MoneyShowUtils.dealNumber((vipServiceBean.getBalance()) +"")+ ", 已抵扣¥" + MoneyShowUtils.dealNumber(0.00+""));
                }else if (getTotalAmountBean.getRange()>0&&getTotalAmountBean.getDeduction()>0){
                    tv_member_card_dikou.setText("余额¥" + MoneyShowUtils.dealNumber((vipServiceBean.getBalance() - getTotalAmountBean.getDeduction()) +"")+ ", 已抵扣¥" + getTotalAmountBean.getDeduction());
                }else if (getTotalAmountBean.getTotalAmount()<=0&&getTotalAmountBean.getDeduction()>0){
                    tv_member_card_dikou.setText("余额¥" + MoneyShowUtils.dealNumber((vipServiceBean.getBalance() - getTotalAmountBean.getDeduction()) +"")+ ", 已抵扣¥" + getTotalAmountBean.getDeduction());
                }*//*else if (getTotalAmountBean != null && vipServiceBean != null&&getTotalAmountBean.getDeduction()<=0){
                    tv_member_card_dikou.setText("余额¥" + MoneyShowUtils.dealNumber((vipServiceBean.getBalance() - getTotalAmountBean.getDeduction()) +"")+ ", 已抵扣¥" + MoneyShowUtils.dealNumber(getTotalAmountBean.getDeduction()+""));
                    llMemberCard.setVisibility(View.GONE);
                }*/
                tvGoodYunfei.setText("+ ¥" + MoneyShowUtils.dealNumber(getTotalAmountBean.getInsure() + ""));
                tvOrderPrice.setMoneyText("" + MoneyShowUtils.changTVsize(MoneyShowUtils.dealNumber(getTotalAmountBean.getTotalAmount() + "")));
                tvGoodMemberZekou.setText("- ¥" + MoneyShowUtils.dealNumber(getTotalAmountBean.getDeduction() + ""));
                tvGoodDiscountZekou.setText("- ¥" + MoneyShowUtils.dealNumber(getTotalAmountBean.getRange() + ""));
                discountSkuMap = getTotalAmountBean.getDiscountSkuMap();


            }

        }


        @Override
        public void onCacheNext(String cache) {


        }


        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", e.getMessage());
        }
    };

    //提交订单获取的订单总金额
    HttpOnNextListener simpleOnNextListenerGetTotalAmountAndSubmit = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {
            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showToast(context, subjects.getMsg());
                return;
            }
            if ((GetTotalAmountBean) subjects.getData() != null) {
                getTotalAmountBean = (GetTotalAmountBean) subjects.getData();
//                tvGoodAllprice.setText("¥" + getTotalAmountBean.getTotalAmount());
                tvGoodYunfei.setText("+ ¥" + MoneyShowUtils.dealNumber(getTotalAmountBean.getInsure() + ""));
                tvOrderPrice.setMoneyText("" + MoneyShowUtils.changTVsize(MoneyShowUtils.dealNumber(getTotalAmountBean.getTotalAmount() + "")));
                tvGoodMemberZekou.setText("- ¥" + MoneyShowUtils.dealNumber(getTotalAmountBean.getDeduction() + ""));
                discountSkuMap = getTotalAmountBean.getDiscountSkuMap();
                //提交订单
                orderSubmit();
            }

        }


        @Override
        public void onCacheNext(String cache) {


        }


        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", e.getMessage());
        }
    };

    //订单提交
    HttpOnNextListener simpleOnNextListenerOrderSubmit = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {

            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showToast(OrderConfirmActivity.this, subjects.getMsg());
//                loading_layout.setStatus(LoadingLayout.ERROR);
                return;
            }
//            loading_layout.setStatus(LoadingLayout.SUCCESS);
            orderSubmitBean = (OrderSubmitBean) subjects.getData();
            if (!getSharedPreferencesUtil().getLogintoken().isEmpty() && orderSubmitBean != null) {
                Map<String, String> paramsBody = new HashMap<>();
                paramsBody.put("orderId", orderSubmitBean.getOrderId() + "");


                paramsBody.put("token", getSharedPreferencesUtil().getLogintoken());
                //历史单位开票信息请求
                final ToPayApi toPayApi = new ToPayApi(OrderConfirmActivity.this, simpleOnNextListenerPayWay);
                toPayApi.setCache(false);
                toPayApi.setMap(paramsBody);
                HttpManager.getInstance().doHttpDeal(toPayApi);

//                loading_layout.setOnReloadListener(new LoadingLayout.OnReloadListener() {
//                    @Override
//                    public void onReload(View v) {
//                        HttpManager.getInstance().doHttpDeal(toPayApi);
//                        loading_layout.setStatus(LoadingLayout.LOADING);
//                    }
//
//                    @Override
//                    public void onReturn(View v) {
//                        onBackPressed();
//                    }
//                });
//                loading_layout.setStatus(LoadingLayout.LOADING);
            } else {
//                loading_layout.setStatus(LoadingLayout.EMPTY);
            }


        }


        @Override
        public void onCacheNext(String cache) {


        }


        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", e.getMessage());
//            if (e instanceof SocketTimeoutException || e instanceof ConnectException) {
//                loading_layout.setStatus(LoadingLayout.NO_NETWORK);
//            } else {
//                loading_layout.setStatus(LoadingLayout.ERROR);
//            }
        }
    };

    //获取支付方式
    HttpOnNextListener simpleOnNextListenerPayWay = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {
            paymentList.clear();
            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showToast(context, subjects.getMsg());
                return;
            }
//            loading_layout.setStatus(LoadingLayout.SUCCESS);

            PayWayBean data = (PayWayBean) subjects.getData();
            paymentList.addAll(data.getPaymentList());
            //选择支付
            selectPay(data);


        }


        @Override
        public void onCacheNext(String cache) {


        }


        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", e.getMessage());
//            if (e instanceof SocketTimeoutException || e instanceof ConnectException) {
//                loading_layout.setStatus(LoadingLayout.NO_NETWORK);
//            } else {
//                loading_layout.setStatus(LoadingLayout.ERROR);
//            }
        }
    };
    //支付提交
    HttpOnNextListener simpleOnNextListenerPaySubmit = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {
            paymentList.clear();
            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showToast(context, subjects.getMsg());
                return;
            }
//            loading_layout.setStatus(LoadingLayout.SUCCESS);
            popupWindow.dismiss();
            if ((PayVo) subjects.getData() != null) {
                final PayVo payVo = (PayVo) subjects.getData();
                if (javaPayUtil == null) {
                    javaPayUtil = new JavaPayUtil(context, new JavaPayUtil.PaySuccessCallBack() {
                        @Override
                        public void paySuccess() {
//                            Intent intent = new Intent();
//                            setResult(MEMBER_REFRESH, intent);
//                            finish();
//                            ToastTools.showToast(OrderConfirmActivity.this,"支付成功");
//                            new Intent(OrderConfirmActivity.this,)

                            Intent intent = new Intent(OrderConfirmActivity.this, PaySucceedActivity.class);
                            if (orderSubmitBean == null) return;
                            intent.putExtra("order_id", orderSubmitBean.getOrderId() + "");
                            intent.putExtra("order_type", payVo.getOrderType());
                            startActivity(intent);
                        }

                        @Override
                        public void expertPaySuccess(String consultType) {

                        }

                        @Override
                        public void payCancel() {
                            Intent intent = new Intent(OrderConfirmActivity.this, PaySucceedActivity.class);
                            if (orderSubmitBean == null) return;
                            intent.putExtra("order_id", orderSubmitBean.getOrderId() + "");
                            intent.putExtra("order_type", payVo.getOrderType());
                            startActivity(intent);
                        }
                    });
                }

                //orderType用来区分是否有余额支付
                int orderType = sureOrderBean.getOrderType();
                payVo.setOrderType(orderType);
                String payId = payVo.getPayId();
                int payID = Integer.parseInt(payId);
                //payId  2  微信支付   3     支付宝     4    银行汇款/转账     6   到店支付     5   余额支付
                if (payID == 2) {
                    javaPayUtil.payByWay(payVo, "WeChat");
                } else if (payID == 3) {
                    javaPayUtil.payByWay(payVo, "Alipay");
                } else if (payID == 4) {
                    Intent intent = new Intent(context, BankPayActivity.class);
                    intent.putExtra("order_id", orderSubmitBean.getOrderId() + "");
                    intent.putExtra("order_sn", orderSubmitBean.getOrderNumber() + "");
                    intent.putExtra("orderType", orderType + "");
                    startActivity(intent);
                } else if (payID == 5 || payID == 5) {
                    Intent intent = new Intent(OrderConfirmActivity.this, PaySucceedActivity.class);
                    intent.putExtra("order_id", payVo.getOrderId() + "");
                    intent.putExtra("order_type", orderType);
                    startActivity(intent);
                } else if (payID == 6) {
                  /*  //  enterType  1是购物车  2是商品详情
                    if (TextUtils.isEmpty(enterType))return;
                    if (enterType.equals("1") || enterType.equals("2")) {*/
                    Intent intent = new Intent(OrderConfirmActivity.this, ShopPayActivity.class);
                    intent.putExtra("order_id", orderSubmitBean.getOrderId() + "");
                    intent.putExtra("order_sn", orderSubmitBean.getOrderNumber() + "");
                    intent.putExtra("orderType", orderType + "");
                    startActivity(intent);
                 /*   } else {
                        Intent intent = new Intent(OrderConfirmActivity.this, ShopPayActivity.class);
                        intent.putExtra("order_id", orderSubmitBean.getOrderId() + "");
                        intent.putExtra("order_sn", orderSubmitBean.getOrderNumber() + "");
                        intent.putExtra("orderType", orderType + "");
                        startActivity(intent);
                    }*/

                }

            }
        }


        @Override
        public void onCacheNext(String cache) {


        }


        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", e.getMessage());
//            if (e instanceof SocketTimeoutException || e instanceof ConnectException) {
//                loading_layout.setStatus(LoadingLayout.NO_NETWORK);
//            } else {
//                loading_layout.setStatus(LoadingLayout.ERROR);
//            }
        }
    };

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        AddressShowBean addressShowBean = (AddressShowBean) intent.getSerializableExtra("addressShow");
        if (addressShowBean != null) {
            tvAddressName.setText(addressShowBean.getAddress());
            tvAddressPhone.setText(addressShowBean.getPhone());
            tvUserName.setText(addressShowBean.getName());
            tv_bottom_address.setText(addressShowBean.getAddress());
            String addressID = addressShowBean.getAddressId();
            addressID = addressID.replace(".0", "");
            this.addressId = Integer.parseInt(addressID);

        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    public String dealString(String value) {
        if (TextUtils.isEmpty(value)) {
            return "";
        } else if (value.equals("null")) {
            return "";
        } else if (value.equals("(null)")) {
            return "";
        } else if (value.equals("<null>")) {
            return "";
        } else {
            return value;
        }

    }

    //为了解决弹出PopupWindow后外部的事件不会分发,既外部的界面不可以点击
    @Override
    public boolean dispatchTouchEvent(MotionEvent event) {
        if (popupWindow != null && popupWindow.isShowing()) {
            return false;
        }
        return super.dispatchTouchEvent(event);

    }

}
